mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
Add map function to gears.table
This commit is contained in:
parent
894c254c42
commit
d22207386f
1 changed files with 15 additions and 0 deletions
|
@ -212,5 +212,20 @@ function gtable.merge(t, set)
|
|||
return t
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue