From c75938bef9e428c41c74738281b1a9eb81c705f7 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 24 Oct 2018 19:13:05 -0400 Subject: [PATCH] prune method in utils --- sys/apis/util.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 3529583..33344fa 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -172,6 +172,20 @@ function Util.deepMerge(obj, args) 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) local tt = { } for k,v in pairs(t) do