Add map function to gears.table

This commit is contained in:
romildo 2017-03-17 21:13:27 -03:00 committed by Emmanuel Lepage Vallee
parent 894c254c42
commit d22207386f
1 changed files with 15 additions and 0 deletions

View File

@ -212,5 +212,20 @@ function gtable.merge(t, set)
return t return t
end end
--- Map a function to a table. The function is applied to each value
-- on the table, returning a table of the results.
-- @class function
-- @name map
-- @tparam function f the function to be applied to each value on the table
-- @tparam table tbl the container table whose values will be operated on
-- @treturn table Return a table of the results
function gtable.map(f, tbl)
local t = {}
for k,v in pairs(tbl) do
t[k] = f(v)
end
return t
end
return gtable return gtable