Skip to content

pipe

const pipe: PipeFn

Defined in: functions/pipe/index.ts:35

Composes functions left-to-right into a single function. The first function receives the initial arguments; each subsequent function receives the previous function’s return value.

Functions to compose, executed in the order provided

A function that applies every fn in sequence

const slug = pipe(
(x: string) => x.trim(),
(x: string) => x.toLowerCase(),
(x: string) => x.replace(/\s+/g, "-"),
);
slug(" Hello World "); // "hello-world"

compose, function composition, flow, left-to-right, pipeline, chain, sequence, combine functions

TC39 pipe operator proposal (https://github.com/tc39/proposal-pipeline-operator)

Error if any argument is not a function

With zero arguments, returns an identity function that passes its first argument through unchanged. Execution is synchronous — if a function returns a Promise, the next function receives the Promise (not the awaited value). Only the first function receives the caller’s this context; subsequent stages are called without this (differs from lodash/flow and es-toolkit/flow, which forward this to every stage).