Last Updated : 20 Oct, 2023
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:
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 number
function cube(number) {
return number * number * number;
}
// Using the _.flow() method
let multiplycube = _.flow([_.multiply, cube]);
// Return the output
console.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 number
function doubled(number) {
return number * 2;
}
// Using the _.flow() method
let adddoubled = _.flow([_.add, doubled]);
// Return the output
console.log(adddoubled(6, 8));
Output:
28
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4