source: node_modules/es-toolkit/dist/compat/function/flowRight.d.mts@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[a762898]1import { Many } from '../_internal/Many.mjs';
2
3/**
4 * Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
5 *
6 * @template A - The type of the arguments.
7 * @template R - The type of the return values.
8 * @param {(a: R) => R} f7 - The seventh function to invoke.
9 * @param {(a: R) => R} f6 - The sixth function to invoke.
10 * @param {(a: R) => R} f5 - The fifth function to invoke.
11 * @param {(a: R) => R} f4 - The fourth function to invoke.
12 * @param {(a: R) => R} f3 - The third function to invoke.
13 * @param {(a: R) => R} f2 - The second function to invoke.
14 * @param {(...args: A) => R} f1 - The first function to invoke.
15 * @returns {(...args: A) => R} Returns the new composite function.
16 *
17 * @example
18 * function square(n) {
19 * return n * n;
20 * }
21 *
22 * var addSquare = flowRight(square, add);
23 * addSquare(1, 2);
24 * // => 9
25 */
26declare function flowRight<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f7: (a: R6) => R7, f6: (a: R5) => R6, f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R7;
27/**
28 * Creates a new function that executes 6 functions in sequence from right to left.
29 * The return value of each function is passed as an argument to the next function.
30 *
31 * @example
32 * const add = (x: number, y: number) => x + y;
33 * const square = (n: number) => n * n;
34 * const double = (n: number) => n * 2;
35 * const toString = (n: number) => String(n);
36 * const append = (s: string) => s + '!';
37 * const length = (s: string) => s.length;
38 *
39 * const combined = flowRight(length, append, toString, double, square, add);
40 * console.log(combined(1, 2)); // 7
41 */
42declare function flowRight<A extends any[], R1, R2, R3, R4, R5, R6>(f6: (a: R5) => R6, f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R6;
43/**
44 * Creates a new function that executes 5 functions in sequence from right to left.
45 * The return value of each function is passed as an argument to the next function.
46 *
47 * @example
48 * const add = (x: number, y: number) => x + y;
49 * const square = (n: number) => n * n;
50 * const double = (n: number) => n * 2;
51 * const toString = (n: number) => String(n);
52 * const append = (s: string) => s + '!';
53 *
54 * const combined = flowRight(append, toString, double, square, add);
55 * console.log(combined(1, 2)); // '18!'
56 */
57declare function flowRight<A extends any[], R1, R2, R3, R4, R5>(f5: (a: R4) => R5, f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R5;
58/**
59 * Creates a new function that executes 4 functions in sequence from right to left.
60 * The return value of each function is passed as an argument to the next function.
61 *
62 * @example
63 * const add = (x: number, y: number) => x + y;
64 * const square = (n: number) => n * n;
65 * const double = (n: number) => n * 2;
66 * const toString = (n: number) => String(n);
67 *
68 * const combined = flowRight(toString, double, square, add);
69 * console.log(combined(1, 2)); // '18'
70 */
71declare function flowRight<A extends any[], R1, R2, R3, R4>(f4: (a: R3) => R4, f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R4;
72/**
73 * Creates a new function that executes 3 functions in sequence from right to left.
74 * The return value of each function is passed as an argument to the next function.
75 *
76 * @example
77 * const add = (x: number, y: number) => x + y;
78 * const square = (n: number) => n * n;
79 * const double = (n: number) => n * 2;
80 *
81 * const combined = flowRight(double, square, add);
82 * console.log(combined(1, 2)); // 18
83 */
84declare function flowRight<A extends any[], R1, R2, R3>(f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R3;
85/**
86 * Creates a new function that executes 2 functions in sequence from right to left.
87 * The return value of the first function is passed as an argument to the second function.
88 *
89 * @example
90 * const add = (x: number, y: number) => x + y;
91 * const square = (n: number) => n * n;
92 *
93 * const combined = flowRight(square, add);
94 * console.log(combined(1, 2)); // 9
95 */
96declare function flowRight<A extends any[], R1, R2>(f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R2;
97/**
98 * Creates a new function that executes the given functions in sequence from right to left.
99 * The return value of each function is passed as an argument to the next function.
100 *
101 * @example
102 * const add = (x: number, y: number) => x + y;
103 * const square = (n: number) => n * n;
104 * const double = (n: number) => n * 2;
105 * const toString = (n: number) => String(n);
106 *
107 * // Pass functions as separate arguments
108 * const combined1 = flowRight(toString, double, square, add);
109 * console.log(combined1(1, 2)); // '18'
110 *
111 * // Pass functions as arrays
112 * const combined2 = flowRight([toString, double], [square, add]);
113 * console.log(combined2(1, 2)); // '18'
114 */
115declare function flowRight(...func: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
116
117export { flowRight };
Note: See TracBrowser for help on using the repository browser.