Skip to content

compose

compose<A, B>(ab): (a) => B

Defined in: Composition/compose.ts:24

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

(a) => B

(a): B

A

B

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:25

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

(b) => C

(a) => B

(a): C

A

C

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:26

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

(c) => D

(b) => C

(a) => B

(a): D

A

D

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:31

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

E

(d) => E

(c) => D

(b) => C

(a) => B

(a): E

A

E

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:37

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

E

F

(e) => F

(d) => E

(c) => D

(b) => C

(a) => B

(a): F

A

F

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:44

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

E

F

G

(f) => G

(e) => F

(d) => E

(c) => D

(b) => C

(a) => B

(a): G

A

G

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:52

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

E

F

G

H

(g) => H

(f) => G

(e) => F

(d) => E

(c) => D

(b) => C

(a) => B

(a): H

A

H

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:61

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

E

F

G

H

I

(h) => I

(g) => H

(f) => G

(e) => F

(d) => E

(c) => D

(b) => C

(a) => B

(a): I

A

I

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition

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

Defined in: Composition/compose.ts:71

Composes functions from right to left, returning a new function. This is the traditional mathematical function composition: (f . g)(x) = f(g(x))

Unlike flow which reads left-to-right, compose reads right-to-left, matching how nested function calls would be written.

A

B

C

D

E

F

G

H

I

J

(i) => J

(h) => I

(g) => H

(f) => G

(e) => F

(d) => E

(c) => D

(b) => C

(a) => B

(a): J

A

J

const addOne = (n: number) => n + 1;
const double = (n: number) => n * 2;

// compose: right-to-left (double first, then addOne)
const composed = compose(addOne, double);
composed(5); // 11 (5 * 2 + 1)

// flow: left-to-right (addOne first, then double)
const flowed = flow(addOne, double);
flowed(5); // 12 ((5 + 1) * 2)

flow for left-to-right composition