Minetest-WorldEditAdditions/worldeditadditions_core/utils/table/table_reduce.lua
Starbeamrainbowlabs 392708b190
initial wea.revolve() implementation
....but it's not tested or hooked up yet.
Next up: a chat command definition so we can test it.
2023-01-21 03:24:44 +00:00

16 lines
563 B
Lua

--- Lua implementation of array.reduce() from Javascript.
-- @param tbl The table to iterate over.
-- @param func The function to call for every element in tbl. Will be passed the following arguments: accumulator, value, index, table. Of course, the provided function need not take this many arguments.
-- @param initial_value The initial value of the accumulator.
local function table_reduce(tbl, func, initial_value)
local acc = initial_value
for key, value in pairs(tbl) do
acc = func(acc, value, key, tbl)
end
return acc
end
return table_reduce