| [a762898] | 1 | import { Many } from '../_internal/Many.js';
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Creates a new function that executes the given functions in sequence. 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 {(...args: A) => R} f1 - The first function to invoke.
|
|---|
| 9 | * @param {(a: R) => R} f2 - The second function to invoke.
|
|---|
| 10 | * @param {(a: R) => R} f3 - The third function to invoke.
|
|---|
| 11 | * @param {(a: R) => R} f4 - The fourth function to invoke.
|
|---|
| 12 | * @param {(a: R) => R} f5 - The fifth function to invoke.
|
|---|
| 13 | * @param {(a: R) => R} f6 - The sixth function to invoke.
|
|---|
| 14 | * @param {(a: R) => R} f7 - The seventh 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 = flow([add, square]);
|
|---|
| 23 | * addSquare(1, 2);
|
|---|
| 24 | * // => 9
|
|---|
| 25 | */
|
|---|
| 26 | declare function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7): (...args: A) => R7;
|
|---|
| 27 | /**
|
|---|
| 28 | * Creates a new function that executes up to 7 functions in sequence, with additional functions flattened.
|
|---|
| 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) => n.toString();
|
|---|
| 36 | *
|
|---|
| 37 | * const combined = flow(add, square, double, toString);
|
|---|
| 38 | * console.log(combined(1, 2)); // "18"
|
|---|
| 39 | */
|
|---|
| 40 | declare function flow<A extends any[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6, f7: (a: R6) => R7, ...func: Array<Many<(a: any) => any>>): (...args: A) => any;
|
|---|
| 41 | /**
|
|---|
| 42 | * Creates a new function that executes 6 functions in sequence.
|
|---|
| 43 | * The return value of each function is passed as an argument to the next function.
|
|---|
| 44 | *
|
|---|
| 45 | * @example
|
|---|
| 46 | * const add = (x: number, y: number) => x + y;
|
|---|
| 47 | * const square = (n: number) => n * n;
|
|---|
| 48 | * const double = (n: number) => n * 2;
|
|---|
| 49 | *
|
|---|
| 50 | * const combined = flow(add, square, double);
|
|---|
| 51 | * console.log(combined(1, 2)); // 18
|
|---|
| 52 | */
|
|---|
| 53 | declare function flow<A extends any[], R1, R2, R3, R4, R5, R6>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5, f6: (a: R5) => R6): (...args: A) => R6;
|
|---|
| 54 | /**
|
|---|
| 55 | * Creates a new function that executes 5 functions in sequence.
|
|---|
| 56 | * The return value of each function is passed as an argument to the next function.
|
|---|
| 57 | *
|
|---|
| 58 | * @example
|
|---|
| 59 | * const add = (x: number, y: number) => x + y;
|
|---|
| 60 | * const square = (n: number) => n * n;
|
|---|
| 61 | * const double = (n: number) => n * 2;
|
|---|
| 62 | *
|
|---|
| 63 | * const combined = flow(add, square, double);
|
|---|
| 64 | * console.log(combined(1, 2)); // 18
|
|---|
| 65 | */
|
|---|
| 66 | declare function flow<A extends any[], R1, R2, R3, R4, R5>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5): (...args: A) => R5;
|
|---|
| 67 | /**
|
|---|
| 68 | * Creates a new function that executes 4 functions in sequence.
|
|---|
| 69 | * The return value of each function is passed as an argument to the next function.
|
|---|
| 70 | *
|
|---|
| 71 | * @example
|
|---|
| 72 | * const add = (x: number, y: number) => x + y;
|
|---|
| 73 | * const square = (n: number) => n * n;
|
|---|
| 74 | * const double = (n: number) => n * 2;
|
|---|
| 75 | *
|
|---|
| 76 | * const combined = flow(add, square, double);
|
|---|
| 77 | * console.log(combined(1, 2)); // 18
|
|---|
| 78 | */
|
|---|
| 79 | declare function flow<A extends any[], R1, R2, R3, R4>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4): (...args: A) => R4;
|
|---|
| 80 | /**
|
|---|
| 81 | * Creates a new function that executes 3 functions in sequence.
|
|---|
| 82 | * The return value of each function is passed as an argument to the next function.
|
|---|
| 83 | *
|
|---|
| 84 | * @example
|
|---|
| 85 | * const add = (x: number, y: number) => x + y;
|
|---|
| 86 | * const square = (n: number) => n * n;
|
|---|
| 87 | * const double = (n: number) => n * 2;
|
|---|
| 88 | *
|
|---|
| 89 | * const combined = flow(add, square, double);
|
|---|
| 90 | * console.log(combined(1, 2)); // 18
|
|---|
| 91 | */
|
|---|
| 92 | declare function flow<A extends any[], R1, R2, R3>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: A) => R3;
|
|---|
| 93 | /**
|
|---|
| 94 | * Creates a new function that executes 2 functions in sequence.
|
|---|
| 95 | * The return value of the first function is passed as an argument to the second function.
|
|---|
| 96 | *
|
|---|
| 97 | * @example
|
|---|
| 98 | * const add = (x: number, y: number) => x + y;
|
|---|
| 99 | * const square = (n: number) => n * n;
|
|---|
| 100 | *
|
|---|
| 101 | * const addThenSquare = flow(add, square);
|
|---|
| 102 | * console.log(addThenSquare(1, 2)); // 9
|
|---|
| 103 | */
|
|---|
| 104 | declare function flow<A extends any[], R1, R2>(f1: (...args: A) => R1, f2: (a: R1) => R2): (...args: A) => R2;
|
|---|
| 105 | /**
|
|---|
| 106 | * Creates a new function that executes the given functions in sequence.
|
|---|
| 107 | * The return value of each function is passed as an argument to the next function.
|
|---|
| 108 | *
|
|---|
| 109 | * @example
|
|---|
| 110 | * const add = (x: number, y: number) => x + y;
|
|---|
| 111 | * const square = (n: number) => n * n;
|
|---|
| 112 | * const double = (n: number) => n * 2;
|
|---|
| 113 | *
|
|---|
| 114 | * const combined = flow(add, square, double);
|
|---|
| 115 | * console.log(combined(1, 2)); // 18
|
|---|
| 116 | */
|
|---|
| 117 | declare function flow(...func: Array<Many<(...args: any[]) => any>>): (...args: any[]) => any;
|
|---|
| 118 |
|
|---|
| 119 | export { flow };
|
|---|