Skip to content

Instantly share code, notes, and snippets.

@holzingk
Forked from FGRibreau/table.filter.lua
Created April 24, 2019 14:59
Show Gist options
  • Save holzingk/b09bed2116ec77ea3082e22ead4c9164 to your computer and use it in GitHub Desktop.
Save holzingk/b09bed2116ec77ea3082e22ead4c9164 to your computer and use it in GitHub Desktop.
Lua table.filter (JavaScript Array::filter equivalent)
-- table.filter({"a", "b", "c", "d"}, function(o, k, i) return o >= "c" end) --> {"c","d"}
--
-- @FGRibreau - Francois-Guillaume Ribreau
-- @Redsmin - A full-feature client for Redis http://redsmin.com
table.filter = function(t, filterIter)
local out = {}
for k, v in pairs(t) do
if filterIter(v, k, t) then out[k] = v end
end
return out
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment