Wednesday, July 3, 2024
HomeLanguagesJavascriptLodash _.curry3() Method

Lodash _.curry3() Method

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




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(a, b, c){
    return a - b - c;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly 
// two arguments
console.log("Subtraction is :",
    gfgFunc(24)(22)(1));


Output:

Subtraction is : 1

Example 2:

Javascript




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


Output: 

Addition is : 49

Example 3:

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y, z){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly
// three arguments
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2")("arg3"));


Output: 

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

Example 4:

Javascript




// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y, z){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly three
// arguments
// For two args, this method returns
// function info
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2"));


Output: 

[Function: mustBeUnary]

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments