simplex/gtable.moon
Paul Liverman III a9dc73a682 Squashed 'utility/' content from commit e918bbe
git-subtree-dir: utility
git-subtree-split: e918bbe5f1ed2f4dbd057223d175cf32bfd7170e
2018-04-23 05:52:56 -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
}