From fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d Mon Sep 17 00:00:00 2001 From: William Boman Date: Sat, 10 Dec 2022 19:55:41 +0100 Subject: feat(functional): add some more functions (#755) --- lua/mason-core/functional/function.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lua/mason-core/functional/function.lua') 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 _ -- cgit v1.2.3-70-g09d2