From d22207386fd9015cba924a03ec7965c9f05fa8c6 Mon Sep 17 00:00:00 2001 From: romildo Date: Fri, 17 Mar 2017 21:13:27 -0300 Subject: [PATCH] Add map function to gears.table --- lib/gears/table.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/gears/table.lua b/lib/gears/table.lua index 95c528a0b..54ceab4be 100644 --- a/lib/gears/table.lua +++ b/lib/gears/table.lua @@ -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