es-toolkit 1.22.0-dev.700 → 1.22.0-dev.702
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/function/flow.d.mts +133 -0
- package/dist/compat/function/flow.d.ts +133 -0
- package/dist/compat/function/flow.mjs +12 -0
- package/dist/compat/function/flowRight.d.mts +145 -0
- package/dist/compat/function/flowRight.d.ts +145 -0
- package/dist/compat/function/flowRight.mjs +12 -0
- package/dist/compat/index.d.mts +2 -2
- package/dist/compat/index.d.ts +2 -2
- package/dist/compat/index.js +33 -17
- package/dist/compat/index.mjs +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
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) | 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
|
+
* const double = (n: number) => n * 2;
|
|
127
|
+
*
|
|
128
|
+
* const combined = flow([add, square], double);
|
|
129
|
+
* console.log(combined(1, 2)); // 18
|
|
130
|
+
*/
|
|
131
|
+
declare function flow(...funcs: Array<((...args: any[]) => any) | Array<(...args: any[]) => any>>): (...args: any[]) => any;
|
|
132
|
+
|
|
133
|
+
export { flow };
|
|
@@ -0,0 +1,133 @@
|
|
|
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) | 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
|
+
* const double = (n: number) => n * 2;
|
|
127
|
+
*
|
|
128
|
+
* const combined = flow([add, square], double);
|
|
129
|
+
* console.log(combined(1, 2)); // 18
|
|
130
|
+
*/
|
|
131
|
+
declare function flow(...funcs: Array<((...args: any[]) => any) | Array<(...args: any[]) => any>>): (...args: any[]) => any;
|
|
132
|
+
|
|
133
|
+
export { flow };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { flatten } from '../../array/flatten.mjs';
|
|
2
|
+
import { flow as flow$1 } from '../../function/flow.mjs';
|
|
3
|
+
|
|
4
|
+
function flow(...funcs) {
|
|
5
|
+
const flattenFuncs = flatten(funcs, 1);
|
|
6
|
+
if (flattenFuncs.some(func => typeof func !== 'function')) {
|
|
7
|
+
throw new TypeError('Expected a function');
|
|
8
|
+
}
|
|
9
|
+
return flow$1(...flattenFuncs);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { flow };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
5
|
+
*
|
|
6
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
7
|
+
*
|
|
8
|
+
* @param {() => R} f The function to invoke.
|
|
9
|
+
* @returns {() => R} Returns the new composite function.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* function noArgFunc() {
|
|
13
|
+
* return 42;
|
|
14
|
+
* }
|
|
15
|
+
* const combined = flowRight(noArgFunc);
|
|
16
|
+
* console.log(combined()); // 42
|
|
17
|
+
*/
|
|
18
|
+
declare function flowRight<R>(f: () => R): () => R;
|
|
19
|
+
/**
|
|
20
|
+
* 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.
|
|
21
|
+
*
|
|
22
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
23
|
+
*
|
|
24
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
25
|
+
*
|
|
26
|
+
* @param {(...args: A) => R} f1 The function to invoke.
|
|
27
|
+
* @returns {(...args: A) => R} Returns the new composite function.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* function oneArgFunc(a: number) {
|
|
31
|
+
* return a * 2;
|
|
32
|
+
* }
|
|
33
|
+
* const combined = flowRight(oneArgFunc);
|
|
34
|
+
* console.log(combined(5)); // 10
|
|
35
|
+
*/
|
|
36
|
+
declare function flowRight<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
|
|
37
|
+
/**
|
|
38
|
+
* 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.
|
|
39
|
+
*
|
|
40
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
41
|
+
*
|
|
42
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
43
|
+
*
|
|
44
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
45
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
46
|
+
* @returns {(...args: A) => R2} Returns the new composite function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const add = (x: number, y: number) => x + y;
|
|
50
|
+
* const square = (n: number) => n * n;
|
|
51
|
+
*
|
|
52
|
+
* const combined = flowRight(square, add);
|
|
53
|
+
* console.log(combined(1, 2)); // 9
|
|
54
|
+
*/
|
|
55
|
+
declare function flowRight<A extends any[], R1, R2>(f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R2;
|
|
56
|
+
/**
|
|
57
|
+
* 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.
|
|
58
|
+
*
|
|
59
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
60
|
+
*
|
|
61
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
62
|
+
*
|
|
63
|
+
* @param {(a: R2) => R3} f3 The function to invoke.
|
|
64
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
65
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
66
|
+
* @returns {(...args: A) => R3} Returns the new composite function.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const add = (x: number, y: number) => x + y;
|
|
70
|
+
* const square = (n: number) => n * n;
|
|
71
|
+
* const double = (n: number) => n * 2;
|
|
72
|
+
*
|
|
73
|
+
* const combined = flowRight(double, square, add);
|
|
74
|
+
* console.log(combined(1, 2)); // 18
|
|
75
|
+
*/
|
|
76
|
+
declare function flowRight<A extends any[], R1, R2, R3>(f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R3;
|
|
77
|
+
/**
|
|
78
|
+
* 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.
|
|
79
|
+
*
|
|
80
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
81
|
+
*
|
|
82
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
83
|
+
*
|
|
84
|
+
* @param {(a: R3) => R4} f4 The function to invoke.
|
|
85
|
+
* @param {(a: R2) => R3} f3 The function to invoke.
|
|
86
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
87
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
88
|
+
* @returns {(...args: A) => R4} Returns the new composite function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const add = (x: number, y: number) => x + y;
|
|
92
|
+
* const square = (n: number) => n * n;
|
|
93
|
+
* const double = (n: number) => n * 2;
|
|
94
|
+
* const toStr = (n: number) => n.toString();
|
|
95
|
+
*
|
|
96
|
+
* const combined = flowRight(toStr, double, square, add);
|
|
97
|
+
* console.log(combined(1, 2)); // '18'
|
|
98
|
+
*/
|
|
99
|
+
declare 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;
|
|
100
|
+
/**
|
|
101
|
+
* 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.
|
|
102
|
+
*
|
|
103
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
104
|
+
*
|
|
105
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
106
|
+
*
|
|
107
|
+
* @param {(a: R4) => R5} f5 The function to invoke.
|
|
108
|
+
* @param {(a: R3) => R4} f4 The function to invoke.
|
|
109
|
+
* @param {(a: R2) => R3} f3 The function to invoke.
|
|
110
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
111
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
112
|
+
* @returns {(...args: A) => R5} Returns the new composite function.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const add = (x: number, y: number) => x + y;
|
|
116
|
+
* const square = (n: number) => n * n;
|
|
117
|
+
* const double = (n: number) => n * 2;
|
|
118
|
+
* const toStr = (n: number) => n.toString();
|
|
119
|
+
* const split = (s: string) => s.split('');
|
|
120
|
+
*
|
|
121
|
+
* const combined = flowRight(split, toStr, double, square, add);
|
|
122
|
+
* console.log(combined(1, 2)); // ['1', '8']
|
|
123
|
+
*/
|
|
124
|
+
declare 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;
|
|
125
|
+
/**
|
|
126
|
+
* 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.
|
|
127
|
+
*
|
|
128
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
129
|
+
*
|
|
130
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
131
|
+
*
|
|
132
|
+
* @param {Array<((...args: any[]) => any) | Array<(...args: any[]) => any>>} funcs The functions to invoke.
|
|
133
|
+
* @returns {(...args: any[]) => any} Returns the new composite function.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const add = (x: number, y: number) => x + y;
|
|
137
|
+
* const square = (n: number) => n * n;
|
|
138
|
+
* const double = (n: number) => n * 2;
|
|
139
|
+
*
|
|
140
|
+
* const combined = flowRight(double, [square, add]);
|
|
141
|
+
* console.log(combined(1, 2)); // 18
|
|
142
|
+
*/
|
|
143
|
+
declare function flowRight(...funcs: Array<((...args: any[]) => any) | Array<(...args: any[]) => any>>): (...args: any[]) => any;
|
|
144
|
+
|
|
145
|
+
export { flowRight };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
5
|
+
*
|
|
6
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
7
|
+
*
|
|
8
|
+
* @param {() => R} f The function to invoke.
|
|
9
|
+
* @returns {() => R} Returns the new composite function.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* function noArgFunc() {
|
|
13
|
+
* return 42;
|
|
14
|
+
* }
|
|
15
|
+
* const combined = flowRight(noArgFunc);
|
|
16
|
+
* console.log(combined()); // 42
|
|
17
|
+
*/
|
|
18
|
+
declare function flowRight<R>(f: () => R): () => R;
|
|
19
|
+
/**
|
|
20
|
+
* 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.
|
|
21
|
+
*
|
|
22
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
23
|
+
*
|
|
24
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
25
|
+
*
|
|
26
|
+
* @param {(...args: A) => R} f1 The function to invoke.
|
|
27
|
+
* @returns {(...args: A) => R} Returns the new composite function.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* function oneArgFunc(a: number) {
|
|
31
|
+
* return a * 2;
|
|
32
|
+
* }
|
|
33
|
+
* const combined = flowRight(oneArgFunc);
|
|
34
|
+
* console.log(combined(5)); // 10
|
|
35
|
+
*/
|
|
36
|
+
declare function flowRight<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
|
|
37
|
+
/**
|
|
38
|
+
* 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.
|
|
39
|
+
*
|
|
40
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
41
|
+
*
|
|
42
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
43
|
+
*
|
|
44
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
45
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
46
|
+
* @returns {(...args: A) => R2} Returns the new composite function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const add = (x: number, y: number) => x + y;
|
|
50
|
+
* const square = (n: number) => n * n;
|
|
51
|
+
*
|
|
52
|
+
* const combined = flowRight(square, add);
|
|
53
|
+
* console.log(combined(1, 2)); // 9
|
|
54
|
+
*/
|
|
55
|
+
declare function flowRight<A extends any[], R1, R2>(f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R2;
|
|
56
|
+
/**
|
|
57
|
+
* 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.
|
|
58
|
+
*
|
|
59
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
60
|
+
*
|
|
61
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
62
|
+
*
|
|
63
|
+
* @param {(a: R2) => R3} f3 The function to invoke.
|
|
64
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
65
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
66
|
+
* @returns {(...args: A) => R3} Returns the new composite function.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const add = (x: number, y: number) => x + y;
|
|
70
|
+
* const square = (n: number) => n * n;
|
|
71
|
+
* const double = (n: number) => n * 2;
|
|
72
|
+
*
|
|
73
|
+
* const combined = flowRight(double, square, add);
|
|
74
|
+
* console.log(combined(1, 2)); // 18
|
|
75
|
+
*/
|
|
76
|
+
declare function flowRight<A extends any[], R1, R2, R3>(f3: (a: R2) => R3, f2: (a: R1) => R2, f1: (...args: A) => R1): (...args: A) => R3;
|
|
77
|
+
/**
|
|
78
|
+
* 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.
|
|
79
|
+
*
|
|
80
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
81
|
+
*
|
|
82
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
83
|
+
*
|
|
84
|
+
* @param {(a: R3) => R4} f4 The function to invoke.
|
|
85
|
+
* @param {(a: R2) => R3} f3 The function to invoke.
|
|
86
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
87
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
88
|
+
* @returns {(...args: A) => R4} Returns the new composite function.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const add = (x: number, y: number) => x + y;
|
|
92
|
+
* const square = (n: number) => n * n;
|
|
93
|
+
* const double = (n: number) => n * 2;
|
|
94
|
+
* const toStr = (n: number) => n.toString();
|
|
95
|
+
*
|
|
96
|
+
* const combined = flowRight(toStr, double, square, add);
|
|
97
|
+
* console.log(combined(1, 2)); // '18'
|
|
98
|
+
*/
|
|
99
|
+
declare 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;
|
|
100
|
+
/**
|
|
101
|
+
* 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.
|
|
102
|
+
*
|
|
103
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
104
|
+
*
|
|
105
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
106
|
+
*
|
|
107
|
+
* @param {(a: R4) => R5} f5 The function to invoke.
|
|
108
|
+
* @param {(a: R3) => R4} f4 The function to invoke.
|
|
109
|
+
* @param {(a: R2) => R3} f3 The function to invoke.
|
|
110
|
+
* @param {(a: R1) => R2} f2 The function to invoke.
|
|
111
|
+
* @param {(...args: A) => R1} f1 The function to invoke.
|
|
112
|
+
* @returns {(...args: A) => R5} Returns the new composite function.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const add = (x: number, y: number) => x + y;
|
|
116
|
+
* const square = (n: number) => n * n;
|
|
117
|
+
* const double = (n: number) => n * 2;
|
|
118
|
+
* const toStr = (n: number) => n.toString();
|
|
119
|
+
* const split = (s: string) => s.split('');
|
|
120
|
+
*
|
|
121
|
+
* const combined = flowRight(split, toStr, double, square, add);
|
|
122
|
+
* console.log(combined(1, 2)); // ['1', '8']
|
|
123
|
+
*/
|
|
124
|
+
declare 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;
|
|
125
|
+
/**
|
|
126
|
+
* 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.
|
|
127
|
+
*
|
|
128
|
+
* The `this` context of the returned function is also passed to the functions provided as parameters.
|
|
129
|
+
*
|
|
130
|
+
* This method is like `flow` except that it creates a function that invokes the given functions from right to left.
|
|
131
|
+
*
|
|
132
|
+
* @param {Array<((...args: any[]) => any) | Array<(...args: any[]) => any>>} funcs The functions to invoke.
|
|
133
|
+
* @returns {(...args: any[]) => any} Returns the new composite function.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const add = (x: number, y: number) => x + y;
|
|
137
|
+
* const square = (n: number) => n * n;
|
|
138
|
+
* const double = (n: number) => n * 2;
|
|
139
|
+
*
|
|
140
|
+
* const combined = flowRight(double, [square, add]);
|
|
141
|
+
* console.log(combined(1, 2)); // 18
|
|
142
|
+
*/
|
|
143
|
+
declare function flowRight(...funcs: Array<((...args: any[]) => any) | Array<(...args: any[]) => any>>): (...args: any[]) => any;
|
|
144
|
+
|
|
145
|
+
export { flowRight };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { flatten } from '../../array/flatten.mjs';
|
|
2
|
+
import { flowRight as flowRight$1 } from '../../function/flowRight.mjs';
|
|
3
|
+
|
|
4
|
+
function flowRight(...funcs) {
|
|
5
|
+
const flattenFuncs = flatten(funcs, 1);
|
|
6
|
+
if (flattenFuncs.some(func => typeof func !== 'function')) {
|
|
7
|
+
throw new TypeError('Expected a function');
|
|
8
|
+
}
|
|
9
|
+
return flowRight$1(...flattenFuncs);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { flowRight };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -57,8 +57,6 @@ export { unary } from '../function/unary.mjs';
|
|
|
57
57
|
export { partial } from '../function/partial.mjs';
|
|
58
58
|
export { partialRight } from '../function/partialRight.mjs';
|
|
59
59
|
export { curryRight } from '../function/curryRight.mjs';
|
|
60
|
-
export { flow } from '../function/flow.mjs';
|
|
61
|
-
export { flowRight } from '../function/flowRight.mjs';
|
|
62
60
|
export { mean } from '../math/mean.mjs';
|
|
63
61
|
export { meanBy } from '../math/meanBy.mjs';
|
|
64
62
|
export { randomInt } from '../math/randomInt.mjs';
|
|
@@ -132,6 +130,8 @@ export { curry } from './function/curry.mjs';
|
|
|
132
130
|
export { debounce } from './function/debounce.mjs';
|
|
133
131
|
export { throttle } from './function/throttle.mjs';
|
|
134
132
|
export { flip } from './function/flip.mjs';
|
|
133
|
+
export { flow } from './function/flow.mjs';
|
|
134
|
+
export { flowRight } from './function/flowRight.mjs';
|
|
135
135
|
export { get } from './object/get.mjs';
|
|
136
136
|
export { set } from './object/set.mjs';
|
|
137
137
|
export { pick } from './object/pick.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -57,8 +57,6 @@ export { unary } from '../function/unary.js';
|
|
|
57
57
|
export { partial } from '../function/partial.js';
|
|
58
58
|
export { partialRight } from '../function/partialRight.js';
|
|
59
59
|
export { curryRight } from '../function/curryRight.js';
|
|
60
|
-
export { flow } from '../function/flow.js';
|
|
61
|
-
export { flowRight } from '../function/flowRight.js';
|
|
62
60
|
export { mean } from '../math/mean.js';
|
|
63
61
|
export { meanBy } from '../math/meanBy.js';
|
|
64
62
|
export { randomInt } from '../math/randomInt.js';
|
|
@@ -132,6 +130,8 @@ export { curry } from './function/curry.js';
|
|
|
132
130
|
export { debounce } from './function/debounce.js';
|
|
133
131
|
export { throttle } from './function/throttle.js';
|
|
134
132
|
export { flip } from './function/flip.js';
|
|
133
|
+
export { flow } from './function/flow.js';
|
|
134
|
+
export { flowRight } from './function/flowRight.js';
|
|
135
135
|
export { get } from './object/get.js';
|
|
136
136
|
export { set } from './object/set.js';
|
|
137
137
|
export { pick } from './object/pick.js';
|