Lodash _.flowRight() Method
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
const _ = require( "lodash" );
function cube(number) {
return number * number * number;
}
let multiplycube =
_.flowRight([cube, _.multiply]);
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
const _ = require( "lodash" );
function doubled(number) {
return number * 2;
}
let adddoubled =
_.flowRight([doubled, _.add]);
console.log(adddoubled(6, 8));
|
Output:
28
Last Updated :
31 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...