Lodash _.flow() method is used to generate a new composite function that returns the result of invoking the provided functions with the binding of the function generated. Each of the successive invocations is provided the return value of the previous.
Syntax:
_.flow([funcs]);
Parameters:
- funcs: This parameter holds the functions that are to be invoked. It is an optional parameter.
Return Value:
This method returns the new composite function.
Example 1: In this example, we are using the _.flow() method and passing a function cube and the _.multiply() method and returning the result.
Javascript
// Requiring the lodash library const _ = require("lodash");Â
// Function to calculate the// Cube of a numberfunction cube(number) {Â Â Â Â return number * number * number;}Â
// Using the _.flow() method let multiplycube = _.flow([_.multiply, cube]);Â
// Return the outputconsole.log(multiplycube(2, 3)); |
 Output:Â
216
Example 2: In this example, we are using the _.flow() method and passing a function doubled and the _.add() method and returning the result.
Javascript
// Requiring the lodash library const _ = require("lodash");Â
// Function to calculate the// double value of a numberfunction doubled(number) {Â Â Â Â return number * 2;}Â
// Using the _.flow() method let adddoubled = _.flow([_.add, doubled]);Â
// Return the outputconsole.log(adddoubled(6, 8)); |
 Output:Â
28
