main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import _curry2 from "./internal/_curry2.js";
|
---|
2 | import curryN from "./curryN.js";
|
---|
3 | /**
|
---|
4 | * Returns a function of arity `n` from a (manually) curried function.
|
---|
5 | * Note that, the returned function is actually a ramda style
|
---|
6 | * curryied function, which can accept one or more arguments in each
|
---|
7 | * function calling.
|
---|
8 | *
|
---|
9 | * @func
|
---|
10 | * @memberOf R
|
---|
11 | * @since v0.14.0
|
---|
12 | * @category Function
|
---|
13 | * @sig Number -> (a -> b -> c ... -> z) -> ((a -> b -> c ...) -> z)
|
---|
14 | * @param {Number} length The arity for the returned function.
|
---|
15 | * @param {Function} fn The function to uncurry.
|
---|
16 | * @return {Function} A new function.
|
---|
17 | * @see R.curry, R.curryN
|
---|
18 | * @example
|
---|
19 | *
|
---|
20 | * const addFour = a => b => c => d => a + b + c + d;
|
---|
21 | *
|
---|
22 | * const uncurriedAddFour = R.uncurryN(4, addFour);
|
---|
23 | * uncurriedAddFour(1, 2, 3, 4); //=> 10
|
---|
24 | */
|
---|
25 |
|
---|
26 | var uncurryN =
|
---|
27 | /*#__PURE__*/
|
---|
28 | _curry2(function uncurryN(depth, fn) {
|
---|
29 | return curryN(depth, function () {
|
---|
30 | var currentDepth = 1;
|
---|
31 | var value = fn;
|
---|
32 | var idx = 0;
|
---|
33 | var endIdx;
|
---|
34 |
|
---|
35 | while (currentDepth <= depth && typeof value === 'function') {
|
---|
36 | endIdx = currentDepth === depth ? arguments.length : idx + value.length;
|
---|
37 | value = value.apply(this, Array.prototype.slice.call(arguments, idx, endIdx));
|
---|
38 | currentDepth += 1;
|
---|
39 | idx = endIdx;
|
---|
40 | }
|
---|
41 |
|
---|
42 | return value;
|
---|
43 | });
|
---|
44 | });
|
---|
45 |
|
---|
46 | export default uncurryN; |
---|
Note:
See
TracBrowser
for help on using the repository browser.