Module lua-nucleo.table-utils

Small table utilities

This file is a part of lua-nucleo library

Info:

  • Copyright: lua-nucleo authors (see file COPYRIGHT for the license)

Fields

empty_table Warning: it is possible to corrupt this with rawset and debug.setmetatable.

Local Functions

toverride_many (t, s, ...)
tappend_many (t, s, ...)
tijoin_many (t, s, ...)
tkeys (t) Keys are ordered in undetermined order
tvalues (t) Values are ordered in undetermined order
tkeysvalues (t) Keys and values are ordered in undetermined order
tflip (t) If table contains multiple keys with the same value, only one key is stored in the result, picked in undetermined way.
tflip_inplace (t) If table contains multiple keys with the same value, only one key is stored in the result, picked in undetermined way.
tiflip (t) If table contains multiple keys with the same value, only the last such key (highest one) is stored in the result.
tset (t)
tiset (t)
tiinsert_args (t, a, ...)
timap_inplace (fn, t, ...)
timap (fn, t, ...)
timap_sliding (fn, t, ...)
tiwalk (fn, t, ...)
tiwalker (fn)
twalk_pairs (fn, t)
tiunique (t)
tgenerate_n (n, generator, ...) Deprecated, use tgenerate_1d_linear instead
tgenerate_1d_linear (n, fn, ...)
tgenerate_2d_linear (w, h, fn, ...)
taccumulate (t, init)
tnormalize (t, sum)
tnormalize_inplace (t, sum)
tclone (t)
tcount_elements (t) Slow
tremap_to_array (fn, t)
tmap_values (fn, t, ...)
torderedset (t)
torderedset_insert (t, v)
torderedset_remove (t, v) Note this operation is really slow
twithdefaults (t, defaults) Handles subtables (is "deep").
tifilter (pred, t, ...)
tsetof (value, t)
tset_many (...)
tidentityset (t)
timapofrecords (t, key)
tivalues (t)
treadonly (value, callbacks, tostring_fn, disable_nil) NOTE: Optimized to be fast at simple value indexing.
treadonly_ex (value, callbacks, tostring_fn, disable_nil) Changes to second return value are guaranteed to affect first one NOTE: Optimized to be fast at simple value indexing.
tmap_kv (fn, t)
tmapofrecordgroups (t, key_name)
timapofrecordgroups (t, key_name)
tilistofrecordfields (t, k)
tipermute_inplace (t, n, count, random)
tkvtorecordlist (t, key_name, value_name)
tgetpath (t, k, nextk, ...)
tsetpath (dest, ...)
tsetpathvalue (value, dest, ...)
tslice (t, start_i, end_i)
tarraylisttohashlist (t, ...)
tarraytohash (t, ...)
tisempty (t)
tifindvalue_nonrecursive (t, v)
tkvlist2kvpairs (t)
tfilterkeylist (t, f, strict)
tkvmap_unpack (fn, t, ...)
tkvlist_to_hash (t)
tmerge_many (...)
tisarray_not (t) Makes table to be treated as JSON object in tisarray()
tisarray (t) Note the empty table is treated as an array
tdeepfilter (predicate, t)
tifindallpermutations (t, results) Finds all permutations of elements in the input linear array table t and puts them into the results table.


Fields

empty_table
Warning: it is possible to corrupt this with rawset and debug.setmetatable.

Local Functions

toverride_many (t, s, ...)

Parameters:

  • t
  • s
  • ...
tappend_many (t, s, ...)

Parameters:

  • t
  • s
  • ...
tijoin_many (t, s, ...)

Parameters:

  • t
  • s
  • ...
tkeys (t)
Keys are ordered in undetermined order

Parameters:

  • t
tvalues (t)
Values are ordered in undetermined order

Parameters:

  • t
tkeysvalues (t)
Keys and values are ordered in undetermined order

Parameters:

  • t
tflip (t)
If table contains multiple keys with the same value, only one key is stored in the result, picked in undetermined way.

Parameters:

  • t
tflip_inplace (t)
If table contains multiple keys with the same value, only one key is stored in the result, picked in undetermined way.

Parameters:

  • t
tiflip (t)
If table contains multiple keys with the same value, only the last such key (highest one) is stored in the result.

Parameters:

  • t
tset (t)

Parameters:

  • t
tiset (t)

Parameters:

  • t
tiinsert_args (t, a, ...)

Parameters:

  • t
  • a
  • ...
timap_inplace (fn, t, ...)

Parameters:

  • fn
  • t
  • ...
timap (fn, t, ...)

Parameters:

  • fn
  • t
  • ...
timap_sliding (fn, t, ...)

Parameters:

  • fn
  • t
  • ...
tiwalk (fn, t, ...)

Parameters:

  • fn
  • t
  • ...
tiwalker (fn)

Parameters:

  • fn
twalk_pairs (fn, t)

Parameters:

  • fn
  • t
tiunique (t)

Parameters:

  • t
tgenerate_n (n, generator, ...)
Deprecated, use tgenerate_1d_linear instead

Parameters:

  • n
  • generator
  • ...
tgenerate_1d_linear (n, fn, ...)

Parameters:

  • n
  • fn
  • ...
tgenerate_2d_linear (w, h, fn, ...)

Parameters:

  • w
  • h
  • fn
  • ...
taccumulate (t, init)

Parameters:

  • t
  • init
tnormalize (t, sum)

Parameters:

  • t
  • sum
tnormalize_inplace (t, sum)

Parameters:

  • t
  • sum
tclone (t)

Parameters:

  • t
tcount_elements (t)
Slow

Parameters:

  • t
tremap_to_array (fn, t)

Parameters:

  • fn
  • t
tmap_values (fn, t, ...)

Parameters:

  • fn
  • t
  • ...
torderedset (t)

Parameters:

  • t
torderedset_insert (t, v)

Parameters:

  • t
  • v

Returns:

    false if item already exists

Or

    true otherwise
torderedset_remove (t, v)
Note this operation is really slow

Parameters:

  • t
  • v

Returns:

    false if item didn't existed

Or

    true otherwise
twithdefaults (t, defaults)
Handles subtables (is "deep"). Does not support recursive defaults tables WARNING: Uses tclone()! Do not use on tables with metatables!

Parameters:

  • t
  • defaults
tifilter (pred, t, ...)

Parameters:

  • pred
  • t
  • ...
tsetof (value, t)

Parameters:

  • value
  • t
tset_many (...)

Parameters:

  • ...
tidentityset (t)

Parameters:

  • t
timapofrecords (t, key)

Parameters:

  • t
  • key
tivalues (t)

Parameters:

  • t
treadonly (value, callbacks, tostring_fn, disable_nil)
NOTE: Optimized to be fast at simple value indexing. Slower on initialization and on table value fetching. WARNING: This does not protect userdata.

Parameters:

  • value
  • callbacks
  • tostring_fn
  • disable_nil
treadonly_ex (value, callbacks, tostring_fn, disable_nil)
Changes to second return value are guaranteed to affect first one NOTE: Optimized to be fast at simple value indexing. Slower on initialization and on table value fetching. WARNING: This does not protect userdata.

Parameters:

  • value
  • callbacks
  • tostring_fn
  • disable_nil
tmap_kv (fn, t)

Parameters:

  • fn
  • t
tmapofrecordgroups (t, key_name)

Parameters:

  • t
  • key_name
timapofrecordgroups (t, key_name)

Parameters:

  • t
  • key_name
tilistofrecordfields (t, k)

Parameters:

  • t
  • k
tipermute_inplace (t, n, count, random)

Parameters:

  • t
  • n
  • count
  • random
tkvtorecordlist (t, key_name, value_name)

Parameters:

  • t
  • key_name
  • value_name
tgetpath (t, k, nextk, ...)

Parameters:

  • t
  • k
  • nextk
  • ...
tsetpath (dest, ...)

Parameters:

  • dest
  • ...
tsetpathvalue (value, dest, ...)

Parameters:

  • value
  • dest
  • ...
tslice (t, start_i, end_i)

Parameters:

  • t
  • start_i
  • end_i
tarraylisttohashlist (t, ...)

Parameters:

  • t
  • ...
tarraytohash (t, ...)

Parameters:

  • t
  • ...
tisempty (t)

Parameters:

  • t
tifindvalue_nonrecursive (t, v)

Parameters:

  • t
  • v
tkvlist2kvpairs (t)

Parameters:

  • t
tfilterkeylist (t, f, strict)

Parameters:

  • t
  • f
  • strict
tkvmap_unpack (fn, t, ...)

Parameters:

  • fn
  • t
  • ...
tkvlist_to_hash (t)

Parameters:

  • t
tmerge_many (...)

Parameters:

  • ...
tisarray_not (t)
Makes table to be treated as JSON object in tisarray()

Parameters:

  • t
tisarray (t)
Note the empty table is treated as an array

Parameters:

  • t

Returns:

    true if a table is an array

Or

    false otherwise
tdeepfilter (predicate, t)

Parameters:

  • predicate
  • t
tifindallpermutations (t, results)
Finds all permutations of elements in the input linear array table t and puts them into the results table.

Parameters:

  • t Input linear array table.
  • results All found permutations will be placed here.

Returns:

    None

Usage:

    local tifindallpermutations
          = import 'lua-nucleo/table-utils.lua'
          {
            'tifindallpermutations'
          }
    
    local permutations0 = tifindallpermutations({ })
    -- permutations0 is { } here
    
    local permutations1 = tifindallpermutations({ 1 }, { { 1 } })
    -- permutations1 is { { 1 } } here
    
    local permutations2 = tifindallpermutations({ 1, 2 })
    -- permutations2 is { { 1, 2 }, { 2, 1 } }
    
    local permutations3 = tifindallpermutations({ 1, 2, 3 })
    -- permutations3 is
    -- {
    --   { 2, 3, 1 },
    --   { 3, 2, 1 },
    --   { 1, 3, 2 },
    --   { 3, 1, 2 },
    --   { 1, 2, 3 },
    --   { 2, 1, 3 }
    -- }
    
    local permutations4 = tifindallpermutations({ 1, 2, 3, 4 })
    -- permutations4 is
    -- {
    --   { 3, 4, 2, 1 },
    --   { 4, 3, 2, 1 },
    --   { 2, 4, 3, 1 },
    --   { 4, 2, 3, 1 },
    --   { 2, 3, 4, 1 },
    --   { 3, 2, 4, 1 },
    --   { 3, 4, 1, 2 },
    --   { 4, 3, 1, 2 },
    --   { 1, 4, 3, 2 },
    --   { 4, 1, 3, 2 },
    --   { 1, 3, 4, 2 },
    --   { 3, 1, 4, 2 },
    --   { 2, 4, 1, 3 },
    --   { 4, 2, 1, 3 },
    --   { 1, 4, 2, 3 },
    --   { 4, 1, 2, 3 },
    --   { 1, 2, 4, 3 },
    --   { 2, 1, 4, 3 },
    --   { 2, 3, 1, 4 },
    --   { 3, 2, 1, 4 },
    --   { 1, 3, 2, 4 },
    --   { 3, 1, 2, 4 },
    --   { 1, 2, 3, 4 },
    --   { 2, 1, 3, 4 }
    -- }
generated by LDoc 1.4.6 Last updated 2021-04-22 13:57:02