mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Bump to v4.0.0.
This commit is contained in:
53
curry.js
Normal file
53
curry.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import createWrapper from './internal/createWrapper';
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var CURRY_FLAG = 8;
|
||||
|
||||
/**
|
||||
* Creates a function that accepts arguments of `func` and either invokes
|
||||
* `func` returning its result, if at least `arity` number of arguments have
|
||||
* been provided, or returns a function that accepts the remaining `func`
|
||||
* arguments, and so on. The arity of `func` may be specified if `func.length`
|
||||
* is not sufficient.
|
||||
*
|
||||
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
||||
* may be used as a placeholder for provided arguments.
|
||||
*
|
||||
* **Note:** This method doesn't set the "length" property of curried functions.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to curry.
|
||||
* @param {number} [arity=func.length] The arity of `func`.
|
||||
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
|
||||
* @returns {Function} Returns the new curried function.
|
||||
* @example
|
||||
*
|
||||
* var abc = function(a, b, c) {
|
||||
* return [a, b, c];
|
||||
* };
|
||||
*
|
||||
* var curried = _.curry(abc);
|
||||
*
|
||||
* curried(1)(2)(3);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* curried(1, 2)(3);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* curried(1, 2, 3);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* // using placeholders
|
||||
* curried(1)(_, 3)(2);
|
||||
* // => [1, 2, 3]
|
||||
*/
|
||||
function curry(func, arity, guard) {
|
||||
arity = guard ? undefined : arity;
|
||||
var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
|
||||
result.placeholder = curry.placeholder;
|
||||
return result;
|
||||
}
|
||||
|
||||
export default curry;
|
||||
Reference in New Issue
Block a user