mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-25 16:43:05 +00:00
Starbeamrainbowlabs
db7b20d485
Also, you can return a value from dofile()!!!! This changes everything.
15 lines
573 B
Lua
15 lines
573 B
Lua
--- Executes the given function on every item in the given table.
|
|
-- Ignores return values that are nil and doesn't insert them into the table.
|
|
-- @param tbl table The table to operate on.
|
|
-- @param func function<any>:any|nil The function to execute on every item in the table.
|
|
-- @returns table A new table containing the return values of the function.
|
|
local function table_map(tbl, func)
|
|
local result = {}
|
|
for i,value in ipairs(tbl) do
|
|
local newval = func(value, i)
|
|
if newval ~= nil then table.insert(result, newval) end
|
|
end
|
|
return result
|
|
end
|
|
|
|
return table_map
|