diff options
author | delta <darkussdelta@gmail.com> | 2024-03-05 14:48:59 +0100 |
---|---|---|
committer | delta <darkussdelta@gmail.com> | 2024-03-05 14:48:59 +0100 |
commit | 510ef8e178929cf5e0c7fd5a5120fecf5f1b79f2 (patch) | |
tree | 3582e5cd7d000335ca94f2a009f3aed57bd86919 /.config/awesome/quarrel/table.lua | |
parent | 95ba8030f722a616cff06c122dcfb2f63e25cf45 (diff) |
idk anymore
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 |