The pipeline pattern — chaining transformations left to right
Nested function calls read inside-out, backwards from the order they actually run — a pipeline is the same computation rearranged so it reads top-to-bottom, in the exact order each step actually happens.
Beginner
2 min read
The problem: nested calls read backwards
const result = capitalize(trim(removeExtraSpaces(rawInput)));
This runs removeExtraSpaces first, then trim, then capitalize — but
reading it left to right, capitalize (the last step) appears first.
Untangling what actually runs before what means reading from the inside out,
which gets genuinely hard to follow once more than two or three functions
are nested.
The fix: a pipeline reads in actual execution order
Now the code reads in the exact order the transformations actually happen —
first removeExtraSpaces, then trim, then capitalize, top to bottom —
matching the mental model of "data flows through a series of steps" far
more directly than nested parentheses do.
pipe vs compose: the same idea, opposite reading order
Some libraries offer compose instead of (or alongside) pipe — the only
difference is which direction the list of functions is read:
// pipe: left to right (first listed, first applied)pipe(f, g, h)(x) // h(g(f(x)))// compose: right to left (last listed, first applied — matches math notation)compose(h, g, f)(x) // h(g(f(x))) — same result, functions listed in reverse
Both produce identical results for the same functions — pipe matches how
most people read left-to-right code and describes the steps in execution
order; compose matches traditional mathematical function notation
(h(g(f(x))), read right to left). Neither is more "correct"; picking one
convention and using it consistently within a codebase is what actually
matters.
Why this matters day to day
The pipeline pattern shows up constantly outside pure functional code too —
Unix shell pipes (cat file | grep error | sort | uniq) are the exact same
idea: data flowing left to right through a sequence of independent
transformations, each one doing one job, composed together instead of
written as one large function trying to do everything at once. Recognizing
"this is a pipeline" is recognizing one of the most transferable patterns in
this entire domain — it shows up under different names in shell scripting,
data processing libraries, and middleware chains alike.