home: vim: lua: utils: add 'partial'

Love me some functional goodness.

This was taken from [1].

[1]: https://reddit.com/r/lua/comments/fh2go5
This commit is contained in:
Bruno BELANYI 2024-07-12 20:34:51 +01:00
parent 966934a8bc
commit bcd9a31bb8

View file

@ -48,4 +48,22 @@ M.list_lsp_clients = function(bufnr)
return names
end
--- partially apply a function with given arguments
M.partial = function(f, ...)
local a = { ... }
local a_len = select("#", ...)
return function(...)
local tmp = { ... }
local tmp_len = select("#", ...)
-- Merge arg lists
for i = 1, tmp_len do
a[a_len + i] = tmp[i]
end
return f(unpack(a, 1, a_len + tmp_len))
end
end
return M