Open In App

Lodash _.flowRight() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.flowRight() method is used to create a new composite function that invokes the provided functions from right to left, where each of the successive invocations is provided the return value of the previous. It is almost the same as the _.flow() method.

Syntax:

_.flowRight(funcs);

Parameters:

  • funcs: This parameter holds the functions to invoke. It is an optional parameter.

Return Value:

This method returns the new composite function.

Example 1: In this example, we are creating a function cube and iterating values using the _.multiply method and passing them into the lodash _.flowRight() method and printing the result in the console.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Function to calculate the
// Cube of a number
function cube(number) {
    return number * number * number;
}
 
// Using the _.flowRight() method 
let multiplycube =
    _.flowRight([cube, _.multiply]);
 
// Printing the output
console.log(multiplycube(2, 3));


Output: 

216

Example 2: In this example, we are creating a function doubled and iterating values using the _.add method and passing them into the lodash _.flowRight() method and printing the result in the console.

Javascript




// Requiring the lodash library 
const _ = require("lodash"); 
 
// Function to calculate the
// double value of a number
function doubled(number) {
  return number * 2;
}
 
// Using the _.flowRight() method 
let adddoubled =
  _.flowRight([doubled, _.add]);
 
// Printing the output
console.log(adddoubled(6, 8));


 Output: 

28 


Last Updated : 31 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads