From d36ad410eef90bfe1a0dddd6ec1904321a5510ed Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 5 Dec 2022 14:46:11 +0100 Subject: [PATCH] feat: util.foreach with sorted keys --- lua/lazy/util.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lua/lazy/util.lua b/lua/lazy/util.lua index 2356f63..5739feb 100644 --- a/lua/lazy/util.lua +++ b/lua/lazy/util.lua @@ -134,4 +134,16 @@ function M.dump(value) return table.concat(result, "") end +---@generic V +---@param t table +---@param fn fun(key:string, value:V) +function M.foreach(t, fn) + ---@type string[] + local keys = vim.tbl_keys(t) + table.sort(keys) + for _, key in ipairs(keys) do + fn(key, t[key]) + end +end + return M