Syntax Of Lodash curry method
_.curry(func, [arity=func.length])
Lodash curry method 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.
Arguments
- func (Function) − The function to curry.
- [arity=func.length] (number) − The arity of func.
Output
- (Function) − Returns the new curried function.
Example
var _ = require('lodash'); var getArray = function(a, b, c) { return [a, b, c]; }; var curried = _.curry(getArray); console.log(curried(1)(2)(3)); console.log(curried(1, 2)(3)); console.log(curried(1, 2, 3));
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
[ 1, 2, 3 ] [ 1, 2, 3 ] [ 1, 2, 3 ]
Next Topic – Click Here
Pingback: Lodash - bindKey method - Adglob Infosystem Pvt Ltd