Lodash _.curry3() Method
Last Updated :
23 Sep, 2020
The Lodash _.curry3() method returns a curried version of the given function but will curry exactly three arguments, no more or less.
Syntax:
_.curry3( 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, c){
return a - b - c;
}
var gfgFunc = _.curry3(fun);
console.log( "Subtraction is :" ,
gfgFunc(24)(22)(1));
|
Output:
Subtraction is : 1
Example 2:
Javascript
var _ = require( 'lodash-contrib' );
function fun(a, b, c){
return a + b + c;
}
var gfgFunc = _.curry3(fun);
console.log( "Addition is :" ,
gfgFunc(25)(23)(1));
|
Output:
Addition is : 49
Example 3:
Javascript
var _ = require( 'lodash-contrib' );
function fun(x, y, z){
return arguments;
}
var gfgFunc = _.curry3(fun);
console.log( "Curried Arguments are :" ,
gfgFunc( "arg1" )( "arg2" )( "arg3" ));
|
Output:
Curried Arguments are : [Arguments]
{ '0': 'arg1', '1': 'arg2', '2': 'arg3' }
Example 4:
Javascript
var _ = require( 'lodash-contrib' );
function fun(x, y, z){
return arguments;
}
var gfgFunc = _.curry3(fun);
console.log( "Curried Arguments are :" ,
gfgFunc( "arg1" )( "arg2" ));
|
Output:
[Function: mustBeUnary]
Share your thoughts in the comments
Please Login to comment...