BeginnerCoder

Lesson 22 — Compose & pipe (expert)

Build pipelines from small functions

pipe(f, g, h) creates a function that sends a value through f, then g, then h — each one gets the previous result. compose is the same but right-to-left. You can build pipe with reduce: start with the input value and apply each function in turn.

const shout = (s) => s.toUpperCase();
const excite = (s) => s + "!";
console.log(excite(shout("hi"))); // HI!  — pipe(shout, excite)("hi")

Why it matters: data cleaning and transformation code becomes a readable list of steps.

Want it another way?
Task

Finish pipe so pipe(inc, double)(3) prints 8 and pipe(double, inc)(3) prints 7.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with JavaScript Intermediate

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.