Minor optimisations to lume.combine(), updated tests

This commit is contained in:
rxi 2015-02-05 21:29:38 +00:00
parent c6ab30cf7d
commit 9cdbc27b66
2 changed files with 15 additions and 1 deletions

View File

@ -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")

View File

@ -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