Closed Kazy closed 3 months ago
@Kazy vim.tbl_add_reverse_lookup
looks like this (with error checking removed):
function vim.tbl_add_reverse_lookup(o)
local keys = vim.tbl_keys(o)
for _, k in ipairs(keys) do
o[o[k]] = k
end
return o
end
So vim.tbl_keys
would be the function to use.
A quick Google shows that adding new keys while iterating is indeed undefined in Lua.
@AThePeanut4 thank you, I've updated it to match that !
Not sure if the
deepcopy
is needed, in some languages iterating while mutating can give weird results.