Underscore.js _.curry3() Method

The Underscore.js _.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 passed as parameter.

Return Value: It returns a curried version of the function.

Note: To execute the below examples, you have to install the underscore-contrib library by using this command prompt and execute the following command.



npm install underscore-contrib

Example 1: 

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-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("Multiplication is :"
    gfgFunc(20)(23)(2));

chevron_right


Output:

Multiplication is : 920

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-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(25)(23)(1));

chevron_right


Output: 

Subtraction is : 1

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-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("a")("b")("c"));

chevron_right


Output: 

Curried Arguments are : [Arguments] { '0': 'a', '1': 'b', '2': 'c' }

Example 4:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-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, it returns function
console.log(gfgFunc("a")("b"));

chevron_right


Output: 

[Function: mustBeUnary]

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.