mirror of https://github.com/folke/lazy.nvim.git
feat: util.foreach with sorted keys
This commit is contained in:
parent
b8d8648d28
commit
d36ad410ee
|
@ -134,4 +134,16 @@ function M.dump(value)
|
||||||
return table.concat(result, "")
|
return table.concat(result, "")
|
||||||
end
|
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
|
return M
|
||||||
|
|
Loading…
Reference in New Issue