mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-10-02 07:22:28 +00:00
Minor optimisations to lume.combine(), updated tests
This commit is contained in:
10
lume.lua
10
lume.lua
@@ -400,8 +400,16 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.combine(...)
|
function lume.combine(...)
|
||||||
|
local n = select('#', ...)
|
||||||
|
if n == 0 then return noop end
|
||||||
|
if n == 1 then
|
||||||
|
local fn = select(1, ...)
|
||||||
|
if not fn then return noop end
|
||||||
|
assert(iscallable(fn), "expected a function or nil")
|
||||||
|
return fn
|
||||||
|
end
|
||||||
local funcs = {}
|
local funcs = {}
|
||||||
for i = 1, select("#", ...) do
|
for i = 1, n do
|
||||||
local fn = select(i, ...)
|
local fn = select(i, ...)
|
||||||
if fn ~= nil then
|
if fn ~= nil then
|
||||||
assert(iscallable(fn), "expected a function or nil")
|
assert(iscallable(fn), "expected a function or nil")
|
||||||
|
@@ -370,6 +370,12 @@ tests["lume.combine"] = function()
|
|||||||
fn = lume.combine(nil, a, nil, b, nil)
|
fn = lume.combine(nil, a, nil, b, nil)
|
||||||
fn(10, 20)
|
fn(10, 20)
|
||||||
testeq( acc, 230 )
|
testeq( acc, 230 )
|
||||||
|
local x = false
|
||||||
|
fn = lume.combine(function() x = true end)
|
||||||
|
fn()
|
||||||
|
testeq( x, true )
|
||||||
|
testeq( type(lume.combine(nil)), "function" )
|
||||||
|
testeq( type(lume.combine()), "function" )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- lume.call
|
-- lume.call
|
||||||
|
Reference in New Issue
Block a user