aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/functional/function.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-12-10 19:55:41 +0100
committerGitHub <noreply@github.com>2022-12-10 18:55:41 +0000
commitfbc72a0c2fe16a93b18ce8facdc9b66e7183f75d (patch)
treebe37b4bd7b0320dbfa3e08dae8c90540c0eaa335 /lua/mason-core/functional/function.lua
parentchore: update generated code (#754) (diff)
downloadmason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.gz
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.bz2
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.lz
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.xz
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.zst
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.zip
feat(functional): add some more functions (#755)
Diffstat (limited to 'lua/mason-core/functional/function.lua')
-rw-r--r--lua/mason-core/functional/function.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/lua/mason-core/functional/function.lua b/lua/mason-core/functional/function.lua
index 6f1806db..863df28e 100644
--- a/lua/mason-core/functional/function.lua
+++ b/lua/mason-core/functional/function.lua
@@ -119,4 +119,22 @@ _.converge = _.curryN(function(fn, fns, val)
return fn(unpack(vim.tbl_map(_.apply_to(val), fns)))
end, 3)
+---@param spec table
+---@param value any
+---@return table
+_.apply_spec = _.curryN(function(spec, value)
+ spec = vim.deepcopy(spec)
+ local function transform(item)
+ if type(item) == "table" then
+ for k, v in pairs(item) do
+ item[k] = transform(v)
+ end
+ return item
+ else
+ return item(value)
+ end
+ end
+ return transform(spec)
+end, 2)
+
return _