JS Built-ins
FunctionalProgrammingbeginner

Pipe β€” left-to-right composition

πŸ“– Usage Example
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const process = pipe(x => x + 1, x => x * 2, x => x + 1);
process(3); // (3+1)*2+1 = 9

pipe() applies functions left-to-right β€” the natural reading order.

Pipe Function

A pipe function applies functions left-to-right, making compositions easier to read.

Challenge: Implement a pipe utility that takes multiple functions and returns a new function applying them left-to-right.

πŸ’‘ Hints (3)
  • β€’ Use reduce to chain function applications
  • β€’ Start with initial value x
  • β€’ Each result becomes input to next function