From 65813e75e6860f08ada8c9123b1016b2548ffd32 Mon Sep 17 00:00:00 2001 From: mikigoalie Date: Tue, 12 Aug 2025 16:42:57 +0200 Subject: [PATCH] feat(imports/table): add table.map (#35) --- imports/table/shared.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/imports/table/shared.lua b/imports/table/shared.lua index 021c603..3570841 100644 --- a/imports/table/shared.lua +++ b/imports/table/shared.lua @@ -123,11 +123,24 @@ local function shuffle(tbl) return tbl end + +---@param tbl table +---@param fn function(value: any, key: any): any +---@return table +local function map(tbl, fn) + local result = {} + for k, v in pairs(tbl) do + result[k] = fn(v, k) + end + return result +end + table.contains = contains table.matches = table_matches table.deepclone = table_deepclone table.merge = table_merge table.shuffle = shuffle +table.map = map local frozenNewIndex = function(self) error(('cannot set values on a frozen table (%s)'):format(self), 2) end local _rawset = rawset