Made callable tables be accepted as functions

This commit is contained in:
rxi
2014-04-17 12:13:50 +01:00
parent 3190d65130
commit cd3c0a1eea

View File

@@ -29,8 +29,8 @@ local absindex = function(len, i)
return i < 0 and (len + i + 1) or i return i < 0 and (len + i + 1) or i
end end
local isfunction = function(x) local iscallable = function(x)
return type(x) == "function" return type(x) == "function" or getmetatable(x).__call ~= nil
end end
@@ -246,7 +246,7 @@ end
function lume.fn(fn, ...) function lume.fn(fn, ...)
assert(isfunction(fn), "expected a function as the first argument") assert(iscallable(fn), "expected a function as the first argument")
local args = {...} local args = {...}
return function(...) return function(...)
local a = lume.merge(lume.clone(args), {...}) local a = lume.merge(lume.clone(args), {...})
@@ -275,7 +275,7 @@ end
function lume.combine(...) function lume.combine(...)
local funcs = {...} local funcs = {...}
assert(lume.all(funcs, isfunction), "expected all arguments to be functions") assert(lume.all(funcs, iscallable), "expected all arguments to be functions")
return function(...) return function(...)
for _, f in ipairs(funcs) do f(...) end for _, f in ipairs(funcs) do f(...) end
end end
@@ -415,7 +415,7 @@ end
local chain_mt = {} local chain_mt = {}
chain_mt.__index = lume.map(lume.filter(lume, isfunction, true), chain_mt.__index = lume.map(lume.filter(lume, iscallable, true),
function(fn) function(fn)
return function(self, ...) return function(self, ...)
self._value = fn(self._value, ...) self._value = fn(self._value, ...)