Open In App

Lodash _.curry2() Method

Last Updated : 23 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




// 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:

Javascript




// 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:

Javascript




// 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' }


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads