UNPKG

1.13 kBJavaScriptView Raw
1import _curry2 from "./internal/_curry2.js";
2import curryN from "./curryN.js";
3/**
4 * Returns a function of arity `n` from a (manually) curried function.
5 *
6 * @func
7 * @memberOf R
8 * @since v0.14.0
9 * @category Function
10 * @sig Number -> (a -> b) -> (a -> c)
11 * @param {Number} length The arity for the returned function.
12 * @param {Function} fn The function to uncurry.
13 * @return {Function} A new function.
14 * @see R.curry
15 * @example
16 *
17 * const addFour = a => b => c => d => a + b + c + d;
18 *
19 * const uncurriedAddFour = R.uncurryN(4, addFour);
20 * uncurriedAddFour(1, 2, 3, 4); //=> 10
21 */
22
23var uncurryN =
24/*#__PURE__*/
25_curry2(function uncurryN(depth, fn) {
26 return curryN(depth, function () {
27 var currentDepth = 1;
28 var value = fn;
29 var idx = 0;
30 var endIdx;
31
32 while (currentDepth <= depth && typeof value === 'function') {
33 endIdx = currentDepth === depth ? arguments.length : idx + value.length;
34 value = value.apply(this, Array.prototype.slice.call(arguments, idx, endIdx));
35 currentDepth += 1;
36 idx = endIdx;
37 }
38
39 return value;
40 });
41});
42
43export default uncurryN;
\No newline at end of file