Skip to content

Commit

Permalink
feat: util.foreach with sorted keys
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 5, 2022
1 parent b8d8648 commit d36ad41
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lua/lazy/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d36ad41

Please sign in to comment.