mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Changed all applicable functions to use iteratee() internally
This commit is contained in:
parent
0b991d7ea5
commit
16e370cdf0
8
lume.lua
8
lume.lua
@ -155,6 +155,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.map(t, fn)
|
function lume.map(t, fn)
|
||||||
|
fn = iteratee(fn)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for k, v in pairs(t) do rtn[k] = fn(v) end
|
for k, v in pairs(t) do rtn[k] = fn(v) end
|
||||||
return rtn
|
return rtn
|
||||||
@ -162,7 +163,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.all(t, fn)
|
function lume.all(t, fn)
|
||||||
fn = fn or function(x) return x end
|
fn = iteratee(fn)
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if not fn(v) then return false end
|
if not fn(v) then return false end
|
||||||
end
|
end
|
||||||
@ -171,7 +172,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.any(t, fn)
|
function lume.any(t, fn)
|
||||||
fn = fn or function(x) return x end
|
fn = iteratee(fn)
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if fn(v) then return true end
|
if fn(v) then return true end
|
||||||
end
|
end
|
||||||
@ -197,6 +198,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.filter(t, fn, retainkeys)
|
function lume.filter(t, fn, retainkeys)
|
||||||
|
fn = iteratee(fn)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(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
|
||||||
@ -222,6 +224,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.match(t, fn)
|
function lume.match(t, fn)
|
||||||
|
fn = iteratee(fn)
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if fn(v) then return v, k end
|
if fn(v) then return v, k end
|
||||||
end
|
end
|
||||||
@ -232,6 +235,7 @@ end
|
|||||||
function lume.count(t, fn)
|
function lume.count(t, fn)
|
||||||
local count = 0
|
local count = 0
|
||||||
if fn then
|
if fn then
|
||||||
|
fn = iteratee(fn)
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if fn(v) then count = count + 1 end
|
if fn(v) then count = count + 1 end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user