| [a762898] | 1 | /**
|
|---|
| 2 | * 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.
|
|---|
| 3 | *
|
|---|
| 4 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 5 | *
|
|---|
| 6 | * @param {() => R} f The function to invoke.
|
|---|
| 7 | * @returns {() => R} Returns the new composite function.
|
|---|
| 8 | *
|
|---|
| 9 | * @example
|
|---|
| 10 | * function noArgFunc() {
|
|---|
| 11 | * return 42;
|
|---|
| 12 | * }
|
|---|
| 13 | *
|
|---|
| 14 | * const combined = flow(noArgFunc);
|
|---|
| 15 | * console.log(combined()); // 42
|
|---|
| 16 | */
|
|---|
| 17 | declare function flow<R>(f: () => R): () => R;
|
|---|
| 18 | /**
|
|---|
| 19 | * 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.
|
|---|
| 20 | *
|
|---|
| 21 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 22 | *
|
|---|
| 23 | * @param {(...args: A) => R} f1 The function to invoke.
|
|---|
| 24 | * @returns {(...args: A) => R} Returns the new composite function.
|
|---|
| 25 | *
|
|---|
| 26 | * @example
|
|---|
| 27 | * function oneArgFunc(a: number) {
|
|---|
| 28 | * return a * 2;
|
|---|
| 29 | * }
|
|---|
| 30 | *
|
|---|
| 31 | * const combined = flow(oneArgFunc);
|
|---|
| 32 | * console.log(combined(5)); // 10
|
|---|
| 33 | */
|
|---|
| 34 | declare function flow<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
|
|---|
| 35 | /**
|
|---|
| 36 | * 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.
|
|---|
| 37 | *
|
|---|
| 38 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 39 | *
|
|---|
| 40 | * @param {(...args: A) => R1} f1 The function to invoke.
|
|---|
| 41 | * @param {(a: R1) => R2} f2 The function to invoke.
|
|---|
| 42 | * @returns {(...args: A) => R2} Returns the new composite function.
|
|---|
| 43 | *
|
|---|
| 44 | * @example
|
|---|
| 45 | * const add = (x: number, y: number) => x + y;
|
|---|
| 46 | * const square = (n: number) => n * n;
|
|---|
| 47 | *
|
|---|
| 48 | * const combined = flow(add, square);
|
|---|
| 49 | * console.log(combined(1, 2)); // 9
|
|---|
| 50 | */
|
|---|
| 51 | declare function flow<A extends any[], R1, R2>(f1: (...args: A) => R1, f2: (a: R1) => R2): (...args: A) => R2;
|
|---|
| 52 | /**
|
|---|
| 53 | * 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.
|
|---|
| 54 | *
|
|---|
| 55 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 56 | *
|
|---|
| 57 | * @param {(...args: A) => R1} f1 The function to invoke.
|
|---|
| 58 | * @param {(a: R1) => R2} f2 The function to invoke.
|
|---|
| 59 | * @param {(a: R2) => R3} f3 The function to invoke.
|
|---|
| 60 | * @returns {(...args: A) => R3} Returns the new composite 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 | *
|
|---|
| 67 | * const combined = flow(add, square, double);
|
|---|
| 68 | * console.log(combined(1, 2)); // 18
|
|---|
| 69 | */
|
|---|
| 70 | declare function flow<A extends any[], R1, R2, R3>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: A) => R3;
|
|---|
| 71 | /**
|
|---|
| 72 | * 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.
|
|---|
| 73 | *
|
|---|
| 74 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 75 | *
|
|---|
| 76 | * @param {(...args: A) => R1} f1 The function to invoke.
|
|---|
| 77 | * @param {(a: R1) => R2} f2 The function to invoke.
|
|---|
| 78 | * @param {(a: R2) => R3} f3 The function to invoke.
|
|---|
| 79 | * @param {(a: R3) => R4} f4 The function to invoke.
|
|---|
| 80 | * @returns {(...args: A) => R4} Returns the new composite function.
|
|---|
| 81 | *
|
|---|
| 82 | * @example
|
|---|
| 83 | * const add = (x: number, y: number) => x + y;
|
|---|
| 84 | * const square = (n: number) => n * n;
|
|---|
| 85 | * const double = (n: number) => n * 2;
|
|---|
| 86 | * const toStr = (n: number) => n.toString();
|
|---|
| 87 | *
|
|---|
| 88 | * const combined = flow(add, square, double, toStr);
|
|---|
| 89 | * console.log(combined(1, 2)); // '18'
|
|---|
| 90 | */
|
|---|
| 91 | 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;
|
|---|
| 92 | /**
|
|---|
| 93 | * 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.
|
|---|
| 94 | *
|
|---|
| 95 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 96 | *
|
|---|
| 97 | * @param {(...args: A) => R1} f1 The function to invoke.
|
|---|
| 98 | * @param {(a: R1) => R2} f2 The function to invoke.
|
|---|
| 99 | * @param {(a: R2) => R3} f3 The function to invoke.
|
|---|
| 100 | * @param {(a: R3) => R4} f4 The function to invoke.
|
|---|
| 101 | * @param {(a: R4) => R5} f5 The function to invoke.
|
|---|
| 102 | * @returns {(...args: A) => R5} Returns the new composite function.
|
|---|
| 103 | *
|
|---|
| 104 | * @example
|
|---|
| 105 | * const add = (x: number, y: number) => x + y;
|
|---|
| 106 | * const square = (n: number) => n * n;
|
|---|
| 107 | * const double = (n: number) => n * 2;
|
|---|
| 108 | * const toStr = (n: number) => n.toString();
|
|---|
| 109 | * const split = (s: string) => s.split('');
|
|---|
| 110 | *
|
|---|
| 111 | * const combined = flow(add, square, double, toStr, split);
|
|---|
| 112 | * console.log(combined(1, 2)); // ['1', '8']
|
|---|
| 113 | */
|
|---|
| 114 | 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;
|
|---|
| 115 | /**
|
|---|
| 116 | * 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.
|
|---|
| 117 | *
|
|---|
| 118 | * The `this` context of the returned function is also passed to the functions provided as parameters.
|
|---|
| 119 | *
|
|---|
| 120 | * @param {Array<(...args: any[]) => any>} funcs The functions to invoke.
|
|---|
| 121 | * @returns {(...args: any[]) => any} Returns the new composite function.
|
|---|
| 122 | *
|
|---|
| 123 | * @example
|
|---|
| 124 | * const add = (x: number, y: number) => x + y;
|
|---|
| 125 | * const square = (n: number) => n * n;
|
|---|
| 126 | *
|
|---|
| 127 | * const combined = flow(add, square);
|
|---|
| 128 | * console.log(combined(1, 2)); // 9
|
|---|
| 129 | */
|
|---|
| 130 | declare function flow(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
|
|---|
| 131 |
|
|---|
| 132 | export { flow };
|
|---|