Lodash _.curry2() Method
Last Updated :
23 Sep, 2020
The Lodash _.curry2() method returns a curried version of the given function but will curry exactly two arguments, no more or less.
Syntax:
_.curry2( fun )
Parameters: This method takes a single parameter as listed above and discussed below.
- fun: This is the given function.
Return Value: It returns a curried version of the function.
Note: To execute the below examples, you have to install the lodash-contrib library by using this command prompt and execute the following command.
npm install lodash-contrib
Example 1:
Javascript
var _ = require( 'lodash-contrib' );
function fun(a, b){
return a * b;
}
var gfgFunc = _.curry2(fun);
console.log( "Multiplication is :" ,
gfgFunc(2)(23));
|
Output:
Multiplication is : 46
Example 2:
Javascript
var _ = require( 'lodash-contrib' );
function fun(a, b){
return a + b;
}
var gfgFunc = _.curry2(fun);
console.log( "Addition is :" , gfgFunc(25)(23));
|
Output:
Addition is : 48
Example 3:
Javascript
var _ = require( 'lodash-contrib' );
function fun(x, y){
return arguments;
}
var gfgFunc = _.curry2(fun);
console.log( "Curried Arguments are :" ,
gfgFunc( "arg1" )( "arg2" ));
|
Output:
Curried Arguments are : [Arguments]
{ '0': 'arg1', '1': 'arg2' }
Share your thoughts in the comments
Please Login to comment...