_.curry(func, [arity=func.length])
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.
Since
2.0.0
Arguments
func
(Function): The function to curry.[arity=func.length]
(number): The arity offunc
.
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]// Curried with placeholders.curried(1)(_, 3)(2);// => [1, 2, 3]
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .