Skip to content

curry

curry<A, B, C>(f, arity?): (a) => (b) => C

Defined in: Composition/curry.ts:26

Converts a 2-, 3-, or 4-argument function into a curried function. The inverse of uncurry.

Arity is read from Function.prototype.length. Functions with rest or default parameters report an unreliable length, so pass the intended arity explicitly. Only arities 2, 3, and 4 are supported; any other inferred arity throws instead of invoking the function early.

A

B

C

(a, b) => C

2

(a) => (b) => C

const add = (a: number, b: number) => a + b;
const curriedAdd = curry(add);
curriedAdd(1)(2); // 3

// Partial application
const addTen = curriedAdd(10);
addTen(5); // 15

// Rest or default parameters need an explicit arity
const tupleSum = (...values: [number, number, number]) => values[0] + values[1] + values[2];
curry(tupleSum, 3)(1)(2)(3); // 6

uncurry for the inverse operation

curry<A, B, C, D>(f, arity?): (a) => (b) => (c) => D

Defined in: Composition/curry.ts:27

Converts a 2-, 3-, or 4-argument function into a curried function. The inverse of uncurry.

Arity is read from Function.prototype.length. Functions with rest or default parameters report an unreliable length, so pass the intended arity explicitly. Only arities 2, 3, and 4 are supported; any other inferred arity throws instead of invoking the function early.

A

B

C

D

(a, b, c) => D

3

(a) => (b) => (c) => D

const add = (a: number, b: number) => a + b;
const curriedAdd = curry(add);
curriedAdd(1)(2); // 3

// Partial application
const addTen = curriedAdd(10);
addTen(5); // 15

// Rest or default parameters need an explicit arity
const tupleSum = (...values: [number, number, number]) => values[0] + values[1] + values[2];
curry(tupleSum, 3)(1)(2)(3); // 6

uncurry for the inverse operation

curry<A, B, C, D, E>(f, arity?): (a) => (b) => (c) => (d) => E

Defined in: Composition/curry.ts:28

Converts a 2-, 3-, or 4-argument function into a curried function. The inverse of uncurry.

Arity is read from Function.prototype.length. Functions with rest or default parameters report an unreliable length, so pass the intended arity explicitly. Only arities 2, 3, and 4 are supported; any other inferred arity throws instead of invoking the function early.

A

B

C

D

E

(a, b, c, d) => E

4

(a) => (b) => (c) => (d) => E

const add = (a: number, b: number) => a + b;
const curriedAdd = curry(add);
curriedAdd(1)(2); // 3

// Partial application
const addTen = curriedAdd(10);
addTen(5); // 15

// Rest or default parameters need an explicit arity
const tupleSum = (...values: [number, number, number]) => values[0] + values[1] + values[2];
curry(tupleSum, 3)(1)(2)(3); // 6

uncurry for the inverse operation