From bcd9a31bb8f61d6355f4c9ee4a6e777087889b09 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 12 Jul 2024 20:34:51 +0100 Subject: [PATCH] home: vim: lua: utils: add 'partial' Love me some functional goodness. This was taken from [1]. [1]: https://reddit.com/r/lua/comments/fh2go5 --- modules/home/vim/lua/ambroisie/utils.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/home/vim/lua/ambroisie/utils.lua b/modules/home/vim/lua/ambroisie/utils.lua index 3d2dd3b..c9e9292 100644 --- a/modules/home/vim/lua/ambroisie/utils.lua +++ b/modules/home/vim/lua/ambroisie/utils.lua @@ -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