source: node_modules/ramda/src/curry.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1var _curry1 =
2/*#__PURE__*/
3require("./internal/_curry1.js");
4
5var curryN =
6/*#__PURE__*/
7require("./curryN.js");
8/**
9 * Returns a curried equivalent of the provided function. The curried function
10 * has two unusual capabilities. First, its arguments needn't be provided one
11 * at a time. If `f` is a ternary function and `g` is `R.curry(f)`, the
12 * following are equivalent:
13 *
14 * - `g(1)(2)(3)`
15 * - `g(1)(2, 3)`
16 * - `g(1, 2)(3)`
17 * - `g(1, 2, 3)`
18 *
19 * Secondly, the special placeholder value [`R.__`](#__) may be used to specify
20 * "gaps", allowing partial application of any combination of arguments,
21 * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
22 * the following are equivalent:
23 *
24 * - `g(1, 2, 3)`
25 * - `g(_, 2, 3)(1)`
26 * - `g(_, _, 3)(1)(2)`
27 * - `g(_, _, 3)(1, 2)`
28 * - `g(_, 2)(1)(3)`
29 * - `g(_, 2)(1, 3)`
30 * - `g(_, 2)(_, 3)(1)`
31 *
32 * Please note that default parameters don't count towards a [function arity](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
33 * and therefore `curry` won't work well with those.
34 *
35 * @func
36 * @memberOf R
37 * @since v0.1.0
38 * @category Function
39 * @sig (* -> a) -> (* -> a)
40 * @param {Function} fn The function to curry.
41 * @return {Function} A new, curried function.
42 * @see R.curryN, R.partial
43 * @example
44 *
45 * const addFourNumbers = (a, b, c, d) => a + b + c + d;
46 * const curriedAddFourNumbers = R.curry(addFourNumbers);
47 * const f = curriedAddFourNumbers(1, 2);
48 * const g = f(3);
49 * g(4); //=> 10
50 *
51 * // R.curry not working well with default parameters
52 * const h = R.curry((a, b, c = 2) => a + b + c);
53 * h(1)(2)(7); //=> Error! (`3` is not a function!)
54 */
55
56
57var curry =
58/*#__PURE__*/
59_curry1(function curry(fn) {
60 return curryN(fn.length, fn);
61});
62
63module.exports = curry;
Note: See TracBrowser for help on using the repository browser.