source: node_modules/es-toolkit/dist/function/curryRight.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

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