mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 15:44:35 +00:00
[added] add remove which holds onto all elements where f(v) returns false
This commit is contained in:
parent
d882127bda
commit
2d24d8e913
@ -80,6 +80,17 @@ function functional.filter(t, f)
|
|||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- inverse of filter - returns a table containing items where f(v) returns false.
|
||||||
|
function functional.remove(t, f)
|
||||||
|
local r = {}
|
||||||
|
for i, v in ipairs(t) do
|
||||||
|
if not f(v, i) then
|
||||||
|
table.insert(r, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
--partitions a sequence based on filter criteria
|
--partitions a sequence based on filter criteria
|
||||||
function functional.partition(t, f)
|
function functional.partition(t, f)
|
||||||
local a = {}
|
local a = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user