Open In App

Lodash _.curryRight() Method

Last Updated : 27 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.curryRight() method is used to return a curried version of the given function where the given arguments are processed from right to left.

Syntax:

_.curryRight(fun);

Parameters:

  • fun: This is the function that should be used in the current version.

Return Value:

This method returns the curried function.

Example 1: In this example, we are using the lodash _.curryRight() method and it invokes the function by right to left parameters.

Javascript




// Defining lodash contrib variable
let _ = require('lodash');
 
// Function to curry
function div(a, b, c) {
    return a / b / c;
}
 
// Using the _.curryRight() method
let curried = _.curryRight(div);
 
console.log("Curried division is :",
    curried(3)(3)(99));


Output:

Curried division is : 11

Example 2: In this example, we are using the lodash _.curryRight() method and it invokes the function by right to left parameters.

Javascript




// Defining lodash contrib variable
let _ = require('lodash');
 
// Function to curry
function div(a, b, c, d) {
    return a - b - c - d;
}
 
// Using the _.curryRight() method
let curried = _.curryRight(div);
 
console.log("Curried Subtraction is :",
    curried(2)(1)(6)(44));


Output: 

Curried Subtraction is : 35

Example 3: In this example, we are using the lodash _.curryRight() method and it invokes the function by right to left parameters.

Javascript




// Defining lodash contrib variable
let _ = require('lodash');
 
// Function to curry
function div(a, b, c) {
    return ("a=" + a + " and b=" + b +
        " and c=" + c);
}
// Using the _.curryRight() method
let curried = _.curryRight(div);
 
console.log(curried("a")("b")("c"));


Output: 

a=c and b=b and c=a


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads