mirror of
https://github.com/kepler155c/opus
synced 2025-02-04 11:19:11 +00:00
prune method in utils
This commit is contained in:
parent
605e923d48
commit
c75938bef9
@ -172,6 +172,20 @@ function Util.deepMerge(obj, args)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- remove table entries if passed function returns false
|
||||||
|
function Util.prune(t, fn)
|
||||||
|
for _,k in pairs(Util.keys(t)) do
|
||||||
|
local v = t[k]
|
||||||
|
if type(v) == 'table' then
|
||||||
|
t[k] = Util.prune(v, fn)
|
||||||
|
end
|
||||||
|
if not fn(t[k]) then
|
||||||
|
t[k] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
function Util.transpose(t)
|
function Util.transpose(t)
|
||||||
local tt = { }
|
local tt = { }
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
|
Loading…
Reference in New Issue
Block a user