Skip to content

uncurry

uncurry<A, B, C>(f): (a, b) => C

Defined in: Composition/uncurry.ts:26

Converts a curried function into a multi-argument function. By default flattens two argument stages. Pass 3 or 4 as the second argument for deeper currying.

The returned value is never inspected or invoked. A curried factory that returns a thunk or a Task keeps returning that function; uncurry only flattens the chosen number of outer stages.

A

B

C

(a) => (b) => C

(a, b) => C

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

// A returned thunk stays a thunk:
const factory = (id: string) => (attempt: number) => () => `${id}:${attempt}`;
const load = uncurry(factory)("user-1", 2);
load(); // "user-1:2"

// Three stages require an explicit arity:
const format = (a: string) => (b: string) => (c: string) => `${a}-${b}-${c}`;
uncurry(format, 3)("A", "B", "C"); // "A-B-C"

flip for reversing curried argument order

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

Defined in: Composition/uncurry.ts:27

Converts a curried function into a multi-argument function. By default flattens two argument stages. Pass 3 or 4 as the second argument for deeper currying.

The returned value is never inspected or invoked. A curried factory that returns a thunk or a Task keeps returning that function; uncurry only flattens the chosen number of outer stages.

A

B

C

D

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

3

(a, b, c) => D

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

// A returned thunk stays a thunk:
const factory = (id: string) => (attempt: number) => () => `${id}:${attempt}`;
const load = uncurry(factory)("user-1", 2);
load(); // "user-1:2"

// Three stages require an explicit arity:
const format = (a: string) => (b: string) => (c: string) => `${a}-${b}-${c}`;
uncurry(format, 3)("A", "B", "C"); // "A-B-C"

flip for reversing curried argument order

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

Defined in: Composition/uncurry.ts:28

Converts a curried function into a multi-argument function. By default flattens two argument stages. Pass 3 or 4 as the second argument for deeper currying.

The returned value is never inspected or invoked. A curried factory that returns a thunk or a Task keeps returning that function; uncurry only flattens the chosen number of outer stages.

A

B

C

D

E

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

4

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

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

// A returned thunk stays a thunk:
const factory = (id: string) => (attempt: number) => () => `${id}:${attempt}`;
const load = uncurry(factory)("user-1", 2);
load(); // "user-1:2"

// Three stages require an explicit arity:
const format = (a: string) => (b: string) => (c: string) => `${a}-${b}-${c}`;
uncurry(format, 3)("A", "B", "C"); // "A-B-C"

flip for reversing curried argument order