ExperimentalGear/scripts/core/table.lua

14 lines
325 B
Lua
Raw Normal View History

---Filter elements of a table where the predicate is true
---@param t table
---@param predicate fun(x: any): boolean
---@return table
function table.filter(t, predicate)
local out = {}
for _, val in ipairs(t) do
if predicate(val) then
table.insert(out, val)
end
end
return out
end