feat: util.foreach with sorted keys

This commit is contained in:
Folke Lemaitre 2022-12-05 14:46:11 +01:00
parent b8d8648d28
commit d36ad410ee
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 12 additions and 0 deletions

View File

@ -134,4 +134,16 @@ function M.dump(value)
return table.concat(result, "")
end
---@generic V
---@param t table<string, V>
---@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