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
const _ = require("lodash");
function cube(number) {
return number * number * number;
}
let multiplycube = _.flow([_.multiply, cube]);
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
const _ = require("lodash");
function doubled(number) {
return number * 2;
}
let adddoubled = _.flow([_.add, doubled]);
console.log(adddoubled(6, 8));
|
Output:
28
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
20 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...