Changed all applicable functions to use iter func based on table

This commit is contained in:
rxi 2015-01-10 14:19:29 +00:00
parent 0c21cfcf5b
commit a42cbb12f0

View File

@ -174,15 +174,17 @@ end
function lume.map(t, fn) function lume.map(t, fn)
fn = iteratee(fn) fn = iteratee(fn)
local iter = getiter(t)
local rtn = {} local rtn = {}
for k, v in pairs(t) do rtn[k] = fn(v) end for k, v in iter(t) do rtn[k] = fn(v) end
return rtn return rtn
end end
function lume.all(t, fn) function lume.all(t, fn)
fn = iteratee(fn) fn = iteratee(fn)
for k, v in pairs(t) do local iter = getiter(t)
for k, v in iter(t) do
if not fn(v) then return false end if not fn(v) then return false end
end end
return true return true
@ -191,7 +193,8 @@ end
function lume.any(t, fn) function lume.any(t, fn)
fn = iteratee(fn) fn = iteratee(fn)
for k, v in pairs(t) do local iter = getiter(t)
for k, v in iter(t) do
if fn(v) then return true end if fn(v) then return true end
end end
return false return false
@ -217,8 +220,9 @@ end
function lume.filter(t, fn, retainkeys) function lume.filter(t, fn, retainkeys)
fn = iteratee(fn) fn = iteratee(fn)
local iter = getiter(t)
local rtn = {} local rtn = {}
for k, v in pairs(t) do 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[retainkeys and k or (#rtn + 1)] = v end
end end
return rtn return rtn
@ -234,7 +238,8 @@ end
function lume.find(t, value) function lume.find(t, value)
for k, v in pairs(t) do local iter = getiter(t)
for k, v in iter(t) do
if v == value then return k end if v == value then return k end
end end
return nil return nil
@ -243,7 +248,8 @@ end
function lume.match(t, fn) function lume.match(t, fn)
fn = iteratee(fn) fn = iteratee(fn)
for k, v in pairs(t) do local iter = getiter(t)
for k, v in iter(t) do
if fn(v) then return v, k end if fn(v) then return v, k end
end end
return nil return nil
@ -252,13 +258,14 @@ end
function lume.count(t, fn) function lume.count(t, fn)
local count = 0 local count = 0
local iter = getiter(t)
if fn then if fn then
fn = iteratee(fn) fn = iteratee(fn)
for k, v in pairs(t) do for k, v in iter(t) do
if fn(v) then count = count + 1 end if fn(v) then count = count + 1 end
end end
else else
for k in pairs(t) do count = count + 1 end for k in iter(t) do count = count + 1 end
end end
return count return count
end end
@ -296,7 +303,8 @@ end
function lume.keys(t) function lume.keys(t)
local rtn = {} local rtn = {}
for k, v in pairs(t) do rtn[#rtn + 1] = k end local iter = getiter(t)
for k, v in iter(t) do rtn[#rtn + 1] = k end
return rtn return rtn
end end