[added] add remove which holds onto all elements where f(v) returns false

This commit is contained in:
Jack Robinson 2020-05-11 12:41:27 +12:00
parent d882127bda
commit 2d24d8e913

View File

@ -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 = {}