mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 15:23:48 +01:00
Functional helpers, table.deep_add_all
This commit is contained in:
parent
ccff2f7673
commit
8f4b73e99d
38
func.lua
38
func.lua
@ -1,6 +1,36 @@
|
||||
no_op = function() end
|
||||
|
||||
function curry(func, ...)
|
||||
local args = {...}
|
||||
return function(...)
|
||||
return func(unpack(args), ...)
|
||||
end
|
||||
local args = { ... }
|
||||
return function(...) return func(unpack(args), ...) end
|
||||
end
|
||||
|
||||
function curry_tail(func, ...)
|
||||
local args = { ... }
|
||||
return function(...) return func(..., unpack(args)) end
|
||||
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
|
||||
end
|
11
table.lua
11
table.lua
@ -235,6 +235,17 @@ function add_all(table, additions)
|
||||
return table
|
||||
end
|
||||
|
||||
function deep_add_all(table, additions)
|
||||
for key, value in pairs(additions) do
|
||||
if type(table[key]) == "table" and type(value) == "table" then
|
||||
deep_add_all(table[key], value)
|
||||
else
|
||||
table[key] = value
|
||||
end
|
||||
end
|
||||
return table
|
||||
end
|
||||
|
||||
function complete(table, completions)
|
||||
for key, value in pairs(completions) do
|
||||
if table[key] == nil then
|
||||
|
Loading…
Reference in New Issue
Block a user