[d24f17c] | 1 | import _arity from "./internal/_arity.js";
|
---|
| 2 | import _curry1 from "./internal/_curry1.js";
|
---|
| 3 | import _curry2 from "./internal/_curry2.js";
|
---|
| 4 | import _curryN from "./internal/_curryN.js";
|
---|
| 5 | /**
|
---|
| 6 | * Returns a curried equivalent of the provided function, with the specified
|
---|
| 7 | * arity. The curried function has two unusual capabilities. First, its
|
---|
| 8 | * arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the
|
---|
| 9 | * following are equivalent:
|
---|
| 10 | *
|
---|
| 11 | * - `g(1)(2)(3)`
|
---|
| 12 | * - `g(1)(2, 3)`
|
---|
| 13 | * - `g(1, 2)(3)`
|
---|
| 14 | * - `g(1, 2, 3)`
|
---|
| 15 | *
|
---|
| 16 | * Secondly, the special placeholder value [`R.__`](#__) may be used to specify
|
---|
| 17 | * "gaps", allowing partial application of any combination of arguments,
|
---|
| 18 | * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
|
---|
| 19 | * the following are equivalent:
|
---|
| 20 | *
|
---|
| 21 | * - `g(1, 2, 3)`
|
---|
| 22 | * - `g(_, 2, 3)(1)`
|
---|
| 23 | * - `g(_, _, 3)(1)(2)`
|
---|
| 24 | * - `g(_, _, 3)(1, 2)`
|
---|
| 25 | * - `g(_, 2)(1)(3)`
|
---|
| 26 | * - `g(_, 2)(1, 3)`
|
---|
| 27 | * - `g(_, 2)(_, 3)(1)`
|
---|
| 28 | *
|
---|
| 29 | * @func
|
---|
| 30 | * @memberOf R
|
---|
| 31 | * @since v0.5.0
|
---|
| 32 | * @category Function
|
---|
| 33 | * @sig Number -> (* -> a) -> (* -> a)
|
---|
| 34 | * @param {Number} length The arity for the returned function.
|
---|
| 35 | * @param {Function} fn The function to curry.
|
---|
| 36 | * @return {Function} A new, curried function.
|
---|
| 37 | * @see R.curry
|
---|
| 38 | * @example
|
---|
| 39 | *
|
---|
| 40 | * const sumArgs = (...args) => R.sum(args);
|
---|
| 41 | *
|
---|
| 42 | * const curriedAddFourNumbers = R.curryN(4, sumArgs);
|
---|
| 43 | * const f = curriedAddFourNumbers(1, 2);
|
---|
| 44 | * const g = f(3);
|
---|
| 45 | * g(4); //=> 10
|
---|
| 46 | */
|
---|
| 47 |
|
---|
| 48 | var curryN =
|
---|
| 49 | /*#__PURE__*/
|
---|
| 50 | _curry2(function curryN(length, fn) {
|
---|
| 51 | if (length === 1) {
|
---|
| 52 | return _curry1(fn);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | return _arity(length, _curryN(length, [], fn));
|
---|
| 56 | });
|
---|
| 57 |
|
---|
| 58 | export default curryN; |
---|