UNPKG

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