Open In App

Lodash _.curry2() Method

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.

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: 




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(a, b){
    return a * b;
}
  
// Making curried function
var gfgFunc = _.curry2(fun);
  
// Only operates for exactly two arguments
console.log("Multiplication is :",
    gfgFunc(2)(23));

Output:

Multiplication is : 46

Example 2:




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(a, b){
    return a + b;
}
  
// Making curried function
var gfgFunc = _.curry2(fun);
  
// Only operates for exactly two arguments
console.log("Addition is :", gfgFunc(25)(23));

Output: 

Addition is : 48

Example 3:




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry2(fun);
  
// Shows only two arguments
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2"));

Output: 

Curried Arguments are : [Arguments] 
    { '0': 'arg1', '1': 'arg2' }

Article Tags :