Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var createCurry = require('../internal/createCurry');
2
3
/** Used to compose bitmasks for wrapper metadata. */
4
var CURRY_FLAG = 8;
5
6
/**
7
* Creates a function that accepts one or more arguments of `func` that when
8
* called either invokes `func` returning its result, if all `func` arguments
9
* have been provided, or returns a function that accepts one or more of the
10
* remaining `func` arguments, and so on. The arity of `func` may be specified
11
* if `func.length` is not sufficient.
12
*
13
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
14
* may be used as a placeholder for provided arguments.
15
*
16
* **Note:** This method does not set the "length" property of curried functions.
17
*
18
* @static
19
* @memberOf _
20
* @category Function
21
* @param {Function} func The function to curry.
22
* @param {number} [arity=func.length] The arity of `func`.
23
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
24
* @returns {Function} Returns the new curried function.
25
* @example
26
*
27
* var abc = function(a, b, c) {
28
* return [a, b, c];
29
* };
30
*
31
* var curried = _.curry(abc);
32
*
33
* curried(1)(2)(3);
34
* // => [1, 2, 3]
35
*
36
* curried(1, 2)(3);
37
* // => [1, 2, 3]
38
*
39
* curried(1, 2, 3);
40
* // => [1, 2, 3]
41
*
42
* // using placeholders
43
* curried(1)(_, 3)(2);
44
* // => [1, 2, 3]
45
*/
46
var curry = createCurry(CURRY_FLAG);
47
48
// Assign default placeholders.
49
curry.placeholder = {};
50
51
module.exports = curry;
52
53