Commit 8d83347b authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

util.filter method for filtering lists

parent d2e2fdf0
......@@ -265,13 +265,11 @@ function Rule:trules()
local function ffilter(ofrags)
if not ofrags or not ofrags[1] or not families then return ofrags end
local res = {}
for i, ofrag in util.listpairs(ofrags) do
if not ofrag.family or util.contains(families, ofrag.family) then
table.insert(res, ofrag)
end
end
return res
return util.filter(ofrags,
function(of)
return not of.family or util.contains(families,
of.family)
end)
end
local function appendtarget(ofrag, target)
......
......@@ -18,6 +18,12 @@ function listpairs(var)
return ipairs(list(var))
end
function filter(var, func)
local res = {}
for i, v in ipairs(var) do if func(v) then table.insert(res, v) end end
return res
end
function map(var, func)
local res = {}
for k, v in pairs(var) do res[k] = func(v) end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment