Changed lume.filter()'s implementation to mimic lume.reject()

This commit is contained in:
rxi 2015-02-20 19:24:48 +00:00
parent 48a4b43640
commit b1c9e3ec2e

View File

@ -280,8 +280,14 @@ function lume.filter(t, fn, retainkeys)
fn = iteratee(fn)
local iter = getiter(t)
local rtn = {}
if retainkeys then
for k, v in iter(t) do
if fn(v) then rtn[retainkeys and k or (#rtn + 1)] = v end
if fn(v) then rtn[k] = v end
end
else
for k, v in iter(t) do
if fn(v) then rtn[#rtn + 1] = v end
end
end
return rtn
end