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]