diff options
Diffstat (limited to '.config/awesome/quarrel/table.lua')
-rw-r--r-- | .config/awesome/quarrel/table.lua | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/.config/awesome/quarrel/table.lua b/.config/awesome/quarrel/table.lua index 13ccbce..2ae15ee 100644 --- a/.config/awesome/quarrel/table.lua +++ b/.config/awesome/quarrel/table.lua @@ -1,17 +1,30 @@ +---@class QuarrelTable local qtable = {} +--- Map a function on each element in the table +---@param t table +---@generic T +---@param f fun(v: T): T +---@return table function qtable.map(t, f) local nt = {} - for k,v in pairs(t) do + for k, v in pairs(t) do nt[k] = f(v) end return nt end +--- Filter a table with a function +---@param t table +---@param f fun(v: any): boolean +---@param dict boolean Whether the supplied table is a dictionary +---@return table function qtable.filter(t, f, dict) local nt = {} - for k,v in pairs(t) do - if not f(v) then goto continue end + for k, v in pairs(t) do + if not f(v) then + goto continue + end if dict then nt[k] = v else @@ -40,9 +53,9 @@ function qtable.onext(t, state) t.__oindex = __gen_oindex(t) key = t.__oindex[1] else - for i = 1,#t.__oindex do + for i = 1, #t.__oindex do if t.__oindex[i] == state then - key = t.__oindex[i+1] + key = t.__oindex[i + 1] end end end |