Skip to content
Related Articles

Related Articles

Improve Article

Lodash _.flow() Method

  • Last Updated : 30 Mar, 2021

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.flow() method is used to generate a new composite function that returns the result of invoking the provided functions with the this binding of the function generated. Each of the successive invocations is provided the return value of the previous.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

_.flow( funcs )

Parameters: This method accepts a single parameter as mentioned above and described below:



  • 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:

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 
var multiplycube = _.flow([_.multiply, cube]);
 
// Return the output
console.log(multiplycube(2, 3));

 

 

Output:

 

216

 



Example 2:  

 

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 
var adddoubled = _.flow([_.add, doubled]);
 
// Return the output
console.log(adddoubled(6, 8));

 

 

Output:

 

28

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :