mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24:35 +00:00
Update functional.lua
This commit is contained in:
parent
120c9658fc
commit
a9b699afdd
@ -64,17 +64,13 @@ function functional.map(t, f)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- map a sequence (see functional.map)
|
-- map a sequence (see functional.map)
|
||||||
-- when the function returns an index, map it there
|
-- the function must return an index and value to map appropriately
|
||||||
function functional.map_index(t, f)
|
function functional.splat(t, f)
|
||||||
local result = {}
|
local result = {}
|
||||||
for i = 1, #t do
|
for i = 1, #t do
|
||||||
local v, pos = f(t[i], i)
|
local v, pos = f(t[i], i)
|
||||||
if v ~= nil then
|
if v ~= nil and pos ~= nil then
|
||||||
if not pos then
|
result[pos] = v
|
||||||
table.insert(result, v)
|
|
||||||
else
|
|
||||||
result[pos] = v
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user