mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 08:53:33 +02:00
feat(util): added LazyVim.memoize
This commit is contained in:
parent
b714f28662
commit
5a11d740e1
1 changed files with 13 additions and 0 deletions
|
@ -268,4 +268,17 @@ for _, level in ipairs({ "info", "warn", "error" }) do
|
|||
end
|
||||
end
|
||||
|
||||
local cache = {} ---@type table<string, any>
|
||||
---@generic T: fun()
|
||||
---@param fn T
|
||||
---@return T
|
||||
function M.memoize(fn)
|
||||
return function(...)
|
||||
local key = vim.inspect({ ... })
|
||||
if cache[key] == nil then
|
||||
cache[key] = fn(...)
|
||||
end
|
||||
return cache[key]
|
||||
end
|
||||
end
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue