mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Renamed lume.set
-> lume.unique
This commit is contained in:
parent
758067dd33
commit
64aae8d473
@ -180,10 +180,10 @@ an error is raised,
|
|||||||
lume.reduce({1, 2, 3}, function(a, b) return a + b end) -- Returns 6
|
lume.reduce({1, 2, 3}, function(a, b) return a + b end) -- Returns 6
|
||||||
```
|
```
|
||||||
|
|
||||||
#### lume.set(t)
|
#### lume.unique(t)
|
||||||
Returns a copy of the `t` array with all the duplicate values removed.
|
Returns a copy of the `t` array with all the duplicate values removed.
|
||||||
```lua
|
```lua
|
||||||
lume.set({2, 1, 2, "cat", "cat"}) -- Returns {1, 2, "cat"}
|
lume.unique({2, 1, 2, "cat", "cat"}) -- Returns {1, 2, "cat"}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### lume.filter(t, fn [, retainkeys])
|
#### lume.filter(t, fn [, retainkeys])
|
||||||
|
2
lume.lua
2
lume.lua
@ -287,7 +287,7 @@ function lume.reduce(t, fn, first)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function lume.set(t)
|
function lume.unique(t)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for k in pairs(lume.invert(t)) do
|
for k in pairs(lume.invert(t)) do
|
||||||
rtn[#rtn + 1] = k
|
rtn[#rtn + 1] = k
|
||||||
|
@ -257,13 +257,13 @@ tests["lume.reduce"] = function()
|
|||||||
tester.test.error(lume.reduce, {}, add)
|
tester.test.error(lume.reduce, {}, add)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- lume.set
|
-- lume.unique
|
||||||
tests["lume.set"] = function()
|
tests["lume.unique"] = function()
|
||||||
testeq( lume.set({}), {} )
|
testeq( lume.unique({}), {} )
|
||||||
local t = lume.set({1, 2, 3, 2, 5, 6, 6})
|
local t = lume.unique({1, 2, 3, 2, 5, 6, 6})
|
||||||
table.sort(t)
|
table.sort(t)
|
||||||
testeq( t, {1, 2, 3, 5, 6} )
|
testeq( t, {1, 2, 3, 5, 6} )
|
||||||
local t = lume.set({"a", "b", "c", "b", "d"})
|
local t = lume.unique({"a", "b", "c", "b", "d"})
|
||||||
table.sort(t)
|
table.sort(t)
|
||||||
testeq( t, {"a", "b", "c", "d"} )
|
testeq( t, {"a", "b", "c", "d"} )
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user