Renamed lume.set -> lume.unique

This commit is contained in:
rxi 2018-03-10 14:54:27 +00:00
parent 758067dd33
commit 64aae8d473
3 changed files with 8 additions and 8 deletions

View File

@ -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])

View File

@ -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

View File

@ -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