From 510ef8e178929cf5e0c7fd5a5120fecf5f1b79f2 Mon Sep 17 00:00:00 2001 From: delta Date: Tue, 5 Mar 2024 14:48:59 +0100 Subject: idk anymore --- .config/awesome/quarrel/table.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to '.config/awesome/quarrel/table.lua') 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 -- cgit v1.2.3