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