simplex2/gtable.moon
Paul Liverman III 311e43ecc1 Squashed 'utility/' content from commit 3616fc8
git-subtree-dir: utility
git-subtree-split: 3616fc80e5a6f6a0739d931118b7f5f3b0efa28e
2018-03-13 02:10:39 -07:00

34 lines
774 B
Plaintext

-- appends n arrays to the end of the first array
append = (tab1, ...) ->
for n = 1, select "#", ...
tab2 = select n, ...
for i = 1, #tab2
tab1[#tab1+1] = tab2[i]
return tab1
-- returns a new table shallow copying data from all arguments
-- later arguments overwrite any keys in earlier arguments
-- ignores non-table arguments (skipping them)
shallow_copy = (...) ->
new = {}
for n = 1, select "#", ...
tab = select n, ...
if "table" == type tab
for k,v in pairs tab
new[k] = v
return new
-- returns a new table with flipped keys and values
invert = (tab) ->
new = {}
for key, value in pairs tab
new[value] = key
return new
{
:append
:shallow_copy
shallow_merge: shallow_copy -- TODO deprecate
:invert
}