source: node_modules/ramda/es/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 
1import _curry1 from "./internal/_curry1.js";
2import curryN from "./curryN.js";
3/**
4 * Returns a curried equivalent of the provided function. The curried function
5 * has two unusual capabilities. First, its arguments needn't be provided one
6 * at a time. If `f` is a ternary function and `g` is `R.curry(f)`, the
7 * following are equivalent:
8 *
9 * - `g(1)(2)(3)`
10 * - `g(1)(2, 3)`
11 * - `g(1, 2)(3)`
12 * - `g(1, 2, 3)`
13 *
14 * Secondly, the special placeholder value [`R.__`](#__) may be used to specify
15 * "gaps", allowing partial application of any combination of arguments,
16 * regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
17 * the following are equivalent:
18 *
19 * - `g(1, 2, 3)`
20 * - `g(_, 2, 3)(1)`
21 * - `g(_, _, 3)(1)(2)`
22 * - `g(_, _, 3)(1, 2)`
23 * - `g(_, 2)(1)(3)`
24 * - `g(_, 2)(1, 3)`
25 * - `g(_, 2)(_, 3)(1)`
26 *
27 * 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)
28 * and therefore `curry` won't work well with those.
29 *
30 * @func
31 * @memberOf R
32 * @since v0.1.0
33 * @category Function
34 * @sig (* -> a) -> (* -> a)
35 * @param {Function} fn The function to curry.
36 * @return {Function} A new, curried function.
37 * @see R.curryN, R.partial
38 * @example
39 *
40 * const addFourNumbers = (a, b, c, d) => a + b + c + d;
41 * const curriedAddFourNumbers = R.curry(addFourNumbers);
42 * const f = curriedAddFourNumbers(1, 2);
43 * const g = f(3);
44 * g(4); //=> 10
45 *
46 * // R.curry not working well with default parameters
47 * const h = R.curry((a, b, c = 2) => a + b + c);
48 * h(1)(2)(7); //=> Error! (`3` is not a function!)
49 */
50
51var curry =
52/*#__PURE__*/
53_curry1(function curry(fn) {
54 return curryN(fn.length, fn);
55});
56
57export default curry;
Note: See TracBrowser for help on using the repository browser.