modlib/func.lua

41 lines
865 B
Lua
Raw Normal View History

2020-12-20 15:21:03 +01:00
no_op = function() end
2020-03-23 20:20:43 +01:00
function curry(func, ...)
2020-12-20 15:21:03 +01:00
local args = { ... }
return function(...) return func(unpack(args), ...) end
end
function curry_tail(func, ...)
local args = { ... }
2021-04-01 12:48:06 +02:00
return function(...) return func(unpack(modlib.table.concat({...}, args))) end
2020-12-20 15:21:03 +01:00
end
function call(...)
local args = { ... }
return function(func) return func(unpack(args)) end
end
function value(val) return function() return val end end
function values(...)
local args = { ... }
return function() return unpack(args) end
end
function override_chain(func, override)
return function(...)
func(...)
return override(...)
end
end
function assert(value, callback)
if not value then
error(callback())
end
2021-03-22 18:17:26 +01:00
end
--+ Calls func using the provided arguments, deepcopies all arguments
function call_by_value(func, ...)
return func(unpack(modlib.table.deepcopy{...}))
2020-03-23 20:20:43 +01:00
end