Wednesday, July 3, 2024
HomeLanguagesJavascriptLodash _.flow() Method

Lodash _.flow() Method

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 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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments