| 1 | /**
|
|---|
| 2 | * 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.
|
|---|
| 3 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 4 | *
|
|---|
| 5 | * @param {() => R} func - The function to curry.
|
|---|
| 6 | * @returns {() => R} A curried function.
|
|---|
| 7 | *
|
|---|
| 8 | * @example
|
|---|
| 9 | * function noArgFunc() {
|
|---|
| 10 | * return 42;
|
|---|
| 11 | * }
|
|---|
| 12 | * const curriedNoArgFunc = curry(noArgFunc);
|
|---|
| 13 | * console.log(curriedNoArgFunc()); // 42
|
|---|
| 14 | */
|
|---|
| 15 | declare function curry<R>(func: () => R): () => R;
|
|---|
| 16 | /**
|
|---|
| 17 | * 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.
|
|---|
| 18 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 19 | *
|
|---|
| 20 | * @param {(p: P) => R} func - The function to curry.
|
|---|
| 21 | * @returns {(p: P) => R} A curried function.
|
|---|
| 22 | *
|
|---|
| 23 | * @example
|
|---|
| 24 | * function oneArgFunc(a: number) {
|
|---|
| 25 | * return a * 2;
|
|---|
| 26 | * }
|
|---|
| 27 | * const curriedOneArgFunc = curry(oneArgFunc);
|
|---|
| 28 | * console.log(curriedOneArgFunc(5)); // 10
|
|---|
| 29 | */
|
|---|
| 30 | declare function curry<P, R>(func: (p: P) => R): (p: P) => R;
|
|---|
| 31 | /**
|
|---|
| 32 | * 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.
|
|---|
| 33 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 34 | *
|
|---|
| 35 | * @param {(p1: P1, p2: P2) => R} func - The function to curry.
|
|---|
| 36 | * @returns {(p1: P1) => (p2: P2) => R} A curried function.
|
|---|
| 37 | *
|
|---|
| 38 | * @example
|
|---|
| 39 | * function twoArgFunc(a: number, b: number) {
|
|---|
| 40 | * return a + b;
|
|---|
| 41 | * }
|
|---|
| 42 | * const curriedTwoArgFunc = curry(twoArgFunc);
|
|---|
| 43 | * const add5 = curriedTwoArgFunc(5);
|
|---|
| 44 | * console.log(add5(10)); // 15
|
|---|
| 45 | */
|
|---|
| 46 | declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2: P2) => R;
|
|---|
| 47 | /**
|
|---|
| 48 | * 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.
|
|---|
| 49 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 50 | *
|
|---|
| 51 | * @param {(p1: P1, p2: P2, p3: P3) => R} func - The function to curry.
|
|---|
| 52 | * @returns {(p1: P1) => (p2: P2) => (p3: P3) => R} A curried function.
|
|---|
| 53 | *
|
|---|
| 54 | * @example
|
|---|
| 55 | * function threeArgFunc(a: number, b: number, c: number) {
|
|---|
| 56 | * return a + b + c;
|
|---|
| 57 | * }
|
|---|
| 58 | * const curriedThreeArgFunc = curry(threeArgFunc);
|
|---|
| 59 | * const add1 = curriedThreeArgFunc(1);
|
|---|
| 60 | * const add3 = add1(2);
|
|---|
| 61 | * console.log(add3(3)); // 6
|
|---|
| 62 | */
|
|---|
| 63 | declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
|
|---|
| 64 | /**
|
|---|
| 65 | * 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.
|
|---|
| 66 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 67 | *
|
|---|
| 68 | * @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
|
|---|
| 69 | * @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
|
|---|
| 70 | *
|
|---|
| 71 | * @example
|
|---|
| 72 | * function fourArgFunc(a: number, b: number, c: number, d: number) {
|
|---|
| 73 | * return a + b + c + d;
|
|---|
| 74 | * }
|
|---|
| 75 | * const curriedFourArgFunc = curry(fourArgFunc);
|
|---|
| 76 | * const add1 = curriedFourArgFunc(1);
|
|---|
| 77 | * const add3 = add1(2);
|
|---|
| 78 | * const add6 = add3(3);
|
|---|
| 79 | * console.log(add6(4)); // 10
|
|---|
| 80 | */
|
|---|
| 81 | declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
|
|---|
| 82 | /**
|
|---|
| 83 | * 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.
|
|---|
| 84 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 85 | *
|
|---|
| 86 | * @param {(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R} func - The function to curry.
|
|---|
| 87 | * @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R} A curried function.
|
|---|
| 88 | *
|
|---|
| 89 | * @example
|
|---|
| 90 | * function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
|
|---|
| 91 | * return a + b + c + d + e;
|
|---|
| 92 | * }
|
|---|
| 93 | * const curriedFiveArgFunc = curry(fiveArgFunc);
|
|---|
| 94 | * const add1 = curriedFiveArgFunc(1);
|
|---|
| 95 | * const add3 = add1(2);
|
|---|
| 96 | * const add6 = add3(3);
|
|---|
| 97 | * const add10 = add6(4);
|
|---|
| 98 | * console.log(add10(5)); // 15
|
|---|
| 99 | */
|
|---|
| 100 | declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
|
|---|
| 101 | /**
|
|---|
| 102 | * 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.
|
|---|
| 103 | * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
|
|---|
| 104 | *
|
|---|
| 105 | * @param {(...args: any[]) => any} func - The function to curry.
|
|---|
| 106 | * @returns {(...args: any[]) => any} A curried function that can be called with a single argument at a time.
|
|---|
| 107 | *
|
|---|
| 108 | * @example
|
|---|
| 109 | * function sum(a: number, b: number, c: number) {
|
|---|
| 110 | * return a + b + c;
|
|---|
| 111 | * }
|
|---|
| 112 | *
|
|---|
| 113 | * const curriedSum = curry(sum);
|
|---|
| 114 | *
|
|---|
| 115 | * // The parameter `a` should be given the value `10`.
|
|---|
| 116 | * const add10 = curriedSum(10);
|
|---|
| 117 | *
|
|---|
| 118 | * // The parameter `b` should be given the value `15`.
|
|---|
| 119 | * const add25 = add10(15);
|
|---|
| 120 | *
|
|---|
| 121 | * // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
|
|---|
| 122 | * const result = add25(5);
|
|---|
| 123 | */
|
|---|
| 124 | declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
|
|---|
| 125 |
|
|---|
| 126 | export { curry };
|
|---|