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