Saturday, October 11, 2025
HomeLanguagesJavascriptUnderscore.js _.pipeline() Method

Underscore.js _.pipeline() Method

The _.pipeline() method takes a list of functions, either as an array or as arguments, and returns a function that takes some value as its argument and runs it through a pipeline of the original functions given in this function.

Syntax:

_.pipeline( func1, func2,..., funcn );

Parameters: This method accepts a single parameter in the form of n functions and hence operate upon given value.

Return Value: This method returns a function.

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. 

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1: passing functions as arguments.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
 
function cb(x) {
    return x * x * x;
};
function tp(x) {
    return 3 * x;
};
function db(x) {
    return 2 * x;
};
let func = _.pipeline(cb, tp, db);
 
console.log(func(5));


Output:

750

Example 2: Passing functions as an array.

Javascript




// Defining underscore contrib variable
const _ = require('underscore-contrib');
 
function cb(x) {
    return x * x * x;
};
function tp(x) {
    return 3 * x;
};
function db(x) {
    return 2 * x;
};
 
let func = _.pipeline([tp, cb, db]);
 
console.log(func(5));


Output:

6750
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!
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11882 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6839 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS