forked from redo/BlockLua
support more+empty args in hooks
This commit is contained in:
@@ -13,8 +13,18 @@ function table.map(f, ...)
|
||||
local u = {}
|
||||
for k,_ in pairs(ts[1]) do
|
||||
local args = {}
|
||||
for j=1,#ts do args[j] = ts[j][i] end
|
||||
u[i] = f(unpack(args))
|
||||
for j=1,#ts do args[j] = ts[j][k] end
|
||||
u[k] = f(unpack(args))
|
||||
end
|
||||
return u
|
||||
end
|
||||
function table.mapk(f, ...)
|
||||
local ts = {...}
|
||||
local u = {}
|
||||
for k,_ in pairs(ts[1]) do
|
||||
local args = {}
|
||||
for j=1,#ts do args[j] = ts[j][k] end
|
||||
u[k] = f(k, unpack(args))
|
||||
end
|
||||
return u
|
||||
end
|
||||
@@ -28,6 +38,16 @@ function table.map_list(f, ...)
|
||||
end
|
||||
return u
|
||||
end
|
||||
function table.mapi_list(f, ...)
|
||||
local ts = {...}
|
||||
local u = {}
|
||||
for i=1,#ts[1] do
|
||||
local args = {}
|
||||
for j=1,#ts do args[j] = ts[j][i] end
|
||||
u[i] = f(i, unpack(args))
|
||||
end
|
||||
return u
|
||||
end
|
||||
-- Swap keys/values
|
||||
function table.swap(t)
|
||||
local u = {}
|
||||
|
||||
Reference in New Issue
Block a user