Skip to content

Instantly share code, notes, and snippets.

@milovtim
Forked from FGRibreau/table.filter.lua
Created March 16, 2018 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milovtim/d7be812d0a2a18f8417794b9e70bb01e to your computer and use it in GitHub Desktop.
Save milovtim/d7be812d0a2a18f8417794b9e70bb01e 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