mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +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
|
||||
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
|
||||
function functional.partition(t, f)
|
||||
local a = {}
|
||||
|
Loading…
Reference in New Issue
Block a user