mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Added lume.keys() and tests, updated docs
This commit is contained in:
parent
ac920c8f5e
commit
de37bd6d65
@ -185,6 +185,9 @@ values the keys.
|
||||
lume.invert({a = "x", b = "y"}) -- returns {x = "a", y = "b"}
|
||||
```
|
||||
|
||||
### lume.keys(t)
|
||||
Returns an array containing each key of the table.
|
||||
|
||||
### lume.clone(t)
|
||||
Returns a shallow copy of the table `t`.
|
||||
|
||||
|
7
lume.lua
7
lume.lua
@ -264,6 +264,13 @@ function lume.invert(t)
|
||||
end
|
||||
|
||||
|
||||
function lume.keys(t)
|
||||
local rtn = {}
|
||||
for k, v in pairs(t) do rtn[#rtn + 1] = k end
|
||||
return rtn
|
||||
end
|
||||
|
||||
|
||||
function lume.clone(t)
|
||||
local rtn = {}
|
||||
for k, v in pairs(t) do rtn[k] = v end
|
||||
|
@ -274,6 +274,16 @@ tests["lume.invert"] = function()
|
||||
testeq( lume.invert(lume.invert{a = 1, b = 2}), {a = 1, b = 2} )
|
||||
end
|
||||
|
||||
-- lume.keys
|
||||
tests["lume.keys"] = function()
|
||||
testeq( lume.keys({}), {} )
|
||||
local t = lume.keys({ aaa = 1, bbb = 2, ccc = 3 })
|
||||
table.sort(t)
|
||||
testeq( t, {"aaa", "bbb", "ccc"} )
|
||||
local t = lume.keys({ "x", "x", "x" })
|
||||
testeq( t, {1, 2, 3} )
|
||||
end
|
||||
|
||||
-- lume.clone
|
||||
tests["lume.clone"] = function()
|
||||
local t = {6, 7, 4, 5}
|
||||
|
Loading…
Reference in New Issue
Block a user