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:
// 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)); |
Output:
Multiplication is : 920
Example 2:
// 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)); |
Output:
Subtraction is : 1
Example 3:
// 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" )); |
Output:
Curried Arguments are : [Arguments] { '0': 'a', '1': 'b', '2': 'c' }
Example 4:
// 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" )); |
Output:
[Function: mustBeUnary]