Skip to content

curry

Import from @varavel/vdl-plugin-sdk/utils/functions.

Utility functions re-exported from es-toolkit (MIT License). See https://github.com/toss/es-toolkit for more details.

Call Signature

function curry<R>(func): () => R;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Type Parameters

Type Parameter
R

Parameters

Parameter Type Description
func () => R The function to curry.

Returns

A curried function.

() => R

Example

function noArgFunc() {
  return 42;
}
const curriedNoArgFunc = curry(noArgFunc);
console.log(curriedNoArgFunc()); // 42

Call Signature

function curry<P, R>(func): (p) => R;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Type Parameters

Type Parameter
P
R

Parameters

Parameter Type Description
func (p) => R The function to curry.

Returns

A curried function.

(p) => R

Example

function oneArgFunc(a: number) {
  return a * 2;
}
const curriedOneArgFunc = curry(oneArgFunc);
console.log(curriedOneArgFunc(5)); // 10

Call Signature

function curry<P1, P2, R>(func): (p1) => (p2) => R;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Type Parameters

Type Parameter
P1
P2
R

Parameters

Parameter Type Description
func (p1, p2) => R The function to curry.

Returns

A curried function.

(p1) => (p2) => R

Example

function twoArgFunc(a: number, b: number) {
  return a + b;
}
const curriedTwoArgFunc = curry(twoArgFunc);
const add5 = curriedTwoArgFunc(5);
console.log(add5(10)); // 15

Call Signature

function curry<P1, P2, P3, R>(func): (p1) => (p2) => (p3) => R;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Type Parameters

Type Parameter
P1
P2
P3
R

Parameters

Parameter Type Description
func (p1, p2, p3) => R The function to curry.

Returns

A curried function.

(p1) => (p2) => (p3) => R

Example

function threeArgFunc(a: number, b: number, c: number) {
  return a + b + c;
}
const curriedThreeArgFunc = curry(threeArgFunc);
const add1 = curriedThreeArgFunc(1);
const add3 = add1(2);
console.log(add3(3)); // 6

Call Signature

function curry<P1, P2, P3, P4, R>(func): (p1) => (p2) => (p3) => (p4) => R;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Type Parameters

Type Parameter
P1
P2
P3
P4
R

Parameters

Parameter Type Description
func (p1, p2, p3, p4) => R The function to curry.

Returns

A curried function.

(p1) => (p2) => (p3) => (p4) => R

Example

function fourArgFunc(a: number, b: number, c: number, d: number) {
  return a + b + c + d;
}
const curriedFourArgFunc = curry(fourArgFunc);
const add1 = curriedFourArgFunc(1);
const add3 = add1(2);
const add6 = add3(3);
console.log(add6(4)); // 10

Call Signature

function curry<P1, P2, P3, P4, P5, R>(func): (p1) => (p2) => (p3) => (p4) => (p5) => R;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Type Parameters

Type Parameter
P1
P2
P3
P4
P5
R

Parameters

Parameter Type Description
func (p1, p2, p3, p4, p5) => R The function to curry.

Returns

A curried function.

(p1) => (p2) => (p3) => (p4) => (p5) => R

Example

function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
  return a + b + c + d + e;
}
const curriedFiveArgFunc = curry(fiveArgFunc);
const add1 = curriedFiveArgFunc(1);
const add3 = add1(2);
const add6 = add3(3);
const add10 = add6(4);
console.log(add10(5)); // 15

Call Signature

function curry(func): (...args) => any;

Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

Parameters

Parameter Type Description
func (...args) => any The function to curry.

Returns

A curried function that can be called with a single argument at a time.

(...args) => any

Example

function sum(a: number, b: number, c: number) {
  return a + b + c;
}

const curriedSum = curry(sum);

// The parameter `a` should be given the value `10`.
const add10 = curriedSum(10);

// The parameter `b` should be given the value `15`.
const add25 = add10(15);

// The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
const result = add25(5);