mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Minor optimisations to lume.combine(), updated tests
This commit is contained in:
parent
c6ab30cf7d
commit
9cdbc27b66
10
lume.lua
10
lume.lua
@ -400,8 +400,16 @@ end
|
||||
|
||||
|
||||
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 = {}
|
||||
for i = 1, select("#", ...) do
|
||||
for i = 1, n do
|
||||
local fn = select(i, ...)
|
||||
if fn ~= nil then
|
||||
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(10, 20)
|
||||
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
|
||||
|
||||
-- lume.call
|
||||
|
Loading…
Reference in New Issue
Block a user