diff options
| author | William Boman <william@redwill.se> | 2022-12-19 11:21:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-19 10:21:24 +0000 |
| commit | 2db93f76da605bccada1be3b020f99b3a67ea791 (patch) | |
| tree | 22e6f8d2e75ab7a4d0ea7a9b316fa8e069608efb | |
| parent | Revert "chore: use pwsh instead of powershell (#706)" (#769) (diff) | |
| download | mason-2db93f76da605bccada1be3b020f99b3a67ea791.tar mason-2db93f76da605bccada1be3b020f99b3a67ea791.tar.gz mason-2db93f76da605bccada1be3b020f99b3a67ea791.tar.bz2 mason-2db93f76da605bccada1be3b020f99b3a67ea791.tar.lz mason-2db93f76da605bccada1be3b020f99b3a67ea791.tar.xz mason-2db93f76da605bccada1be3b020f99b3a67ea791.tar.zst mason-2db93f76da605bccada1be3b020f99b3a67ea791.zip | |
fix(functional): spread function args in _.apply (#770)
| -rw-r--r-- | lua/mason-core/functional/function.lua | 2 | ||||
| -rw-r--r-- | tests/mason-core/functional/function_spec.lua | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lua/mason-core/functional/function.lua b/lua/mason-core/functional/function.lua index 863df28e..59d3af26 100644 --- a/lua/mason-core/functional/function.lua +++ b/lua/mason-core/functional/function.lua @@ -107,7 +107,7 @@ end, 2) ---@param args V[] ---@return R _.apply = _.curryN(function(fn, args) - return fn(args) + return fn(unpack(args)) end, 2) ---@generic T, V diff --git a/tests/mason-core/functional/function_spec.lua b/tests/mason-core/functional/function_spec.lua index 6b36b53b..9f5189fd 100644 --- a/tests/mason-core/functional/function_spec.lua +++ b/tests/mason-core/functional/function_spec.lua @@ -147,6 +147,14 @@ describe("functional: function", function() assert.spy(fn).was_called_with(42) end) + it("should apply function", function() + local max = spy.new(math.max) + local max_fn = _.apply(max) + assert.equals(42, max_fn { 1, 2, 3, 4, 5, 6, 7, 8, 9, 42, 10, 8, 4 }) + assert.spy(max).was_called(1) + assert.spy(max).was_called_with(1, 2, 3, 4, 5, 6, 7, 8, 9, 42, 10, 8, 4) + end) + it("should apply value to function", function() local agent = spy.new() _.apply_to("007", agent) |
