Skip to main content

pipe()

pipe<A>(a): A

pipe<A, B>(a, ab): B

pipe<A, B, C>(a, ab, bc): C

pipe<A, B, C, D>(a, ab, bc, cd): D

Show 16 more signatures

pipe<A, B, C, D, E>(a, ab, bc, cd, de): E

pipe<A, B, C, D, E, F>(a, ab, bc, cd, de, ef): F

pipe<A, B, C, D, E, F, G>(a, ab, bc, cd, de, ef, fg): G

pipe<A, B, C, D, E, F, G, H>(a, ab, bc, cd, de, ef, fg, gh): H

pipe<A, B, C, D, E, F, G, H, I>(a, ab, bc, cd, de, ef, fg, gh, hi): I

pipe<A, B, C, D, E, F, G, H, I, J>(a, ab, bc, cd, de, ef, fg, gh, hi, ij): J

pipe<A, B, C, D, E, F, G, H, I, J, K>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk): K

pipe<A, B, C, D, E, F, G, H, I, J, K, L>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl): L

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm): M

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn): N

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no): O

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op): P

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq): Q

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr): R

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr, rs): S

pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr, rs, st): T

Composes functions left-to-right, passing the result of each to the next.

note

Supports up to 20 functions with full type inference.


Type Parametersโ€‹

A: Aโ€‹

The type of the initial value.

B: Bโ€‹

C: Cโ€‹

D: Dโ€‹

E: Eโ€‹

F: Fโ€‹

G: Gโ€‹

H: Hโ€‹

I: Iโ€‹

J: Jโ€‹

K: Kโ€‹

L: Lโ€‹

M: Mโ€‹

N: Nโ€‹

O: Oโ€‹

P: Pโ€‹

Q: Qโ€‹

R: Rโ€‹

S: Sโ€‹

T: Tโ€‹


Parametersโ€‹

Overload 1:

a: Aโ€‹

Overload 2:

a: Aโ€‹

ab: (a) => Bโ€‹

Overload 3:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

Overload 4:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

Show 16 more overloads

Overload 5:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

Overload 6:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

Overload 7:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

Overload 8:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

Overload 9:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

Overload 10:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

Overload 11:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

Overload 12:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

Overload 13:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

Overload 14:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

Overload 15:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

no: (n) => Oโ€‹

Overload 16:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

no: (n) => Oโ€‹

op: (o) => Pโ€‹

Overload 17:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

no: (n) => Oโ€‹

op: (o) => Pโ€‹

pq: (p) => Qโ€‹

Overload 18:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

no: (n) => Oโ€‹

op: (o) => Pโ€‹

pq: (p) => Qโ€‹

qr: (q) => Rโ€‹

Overload 19:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

no: (n) => Oโ€‹

op: (o) => Pโ€‹

pq: (p) => Qโ€‹

qr: (q) => Rโ€‹

rs: (r) => Sโ€‹

Overload 20:

a: Aโ€‹

ab: (a) => Bโ€‹

bc: (b) => Cโ€‹

cd: (c) => Dโ€‹

de: (d) => Eโ€‹

ef: (e) => Fโ€‹

fg: (f) => Gโ€‹

gh: (g) => Hโ€‹

hi: (h) => Iโ€‹

ij: (i) => Jโ€‹

jk: (j) => Kโ€‹

kl: (k) => Lโ€‹

lm: (l) => Mโ€‹

mn: (m) => Nโ€‹

no: (n) => Oโ€‹

op: (o) => Pโ€‹

pq: (p) => Qโ€‹

qr: (q) => Rโ€‹

rs: (r) => Sโ€‹

st: (s) => Tโ€‹


Returns: Aโ€‹

The result of applying all transformations.


Sinceโ€‹

2.0.0


Performanceโ€‹

Inline execution for 0-5 functions (~2x faster), loop for 6+.


Also known asโ€‹

chain (Radashi) ยท flow (Lodash, es-toolkit) ยท pipe (Remeda, Ramda, Effect) ยท โŒ (Modern Dash, Antfu)


Exampleโ€‹

pipe(5, (x) => x * 2, (x) => x + 1);
// => 11

pipe(
'hello',
(s) => s.toUpperCase(),
(s) => s.split(''),
(arr) => arr.reverse(),
(arr) => arr.join('')
);
// => 'OLLEH'

How it works?โ€‹

Composes functions left-to-right, passing each result to the next function.

Step-by-Stepโ€‹

String Transformation Exampleโ€‹

pipe vs flowRightโ€‹

pipeflowRight
DirectionLeft โ†’ RightRight โ†’ Left
First argInitial valueLast function
Mental modelData flows throughMath composition

Use Casesโ€‹

Function composition and chaining ๐Ÿ“Œโ€‹

Compose multiple functions in a readable left-to-right manner. Essential for functional programming and clean data processing workflows.

const add = (n) => n + 1;
const double = (n) => n * 2;
const square = (n) => n * n;

const process = pipe(add, double, square);
// ((n + 1) * 2) ^ 2

process(2); // ((2+1)*2)^2 = 36

Data transformation pipelinesโ€‹

Transform data through multiple steps with type-safe function composition. Essential for complex data processing and ETL operations.

const cleanInput = pipe(
(s) => s.trim(),
(s) => s.toLowerCase(),
(s) => s.replace(/\s+/g, "-")
);

cleanInput(" Hello World "); // "hello-world"

Process API response through a full pipelineโ€‹

Chain fetch, parse, normalize, and filter steps into a single readable pipeline. The real-world pattern developers write daily when consuming API data.

const getActiveUsers = pipe(
(response: Response) => response.json(),
(data: { users: User[] }) => data.users,
(users) => users.filter((u) => u.isActive),
(users) => users.map((u) => ({ id: u.id, name: u.name, email: u.email })),
);

const users = await fetch("/api/users").then(getActiveUsers);
// Raw response โ†’ parsed JSON โ†’ extracted array โ†’ filtered active โ†’ picked fields