es-toolkit 1.51.0-dev.2074 → 1.51.0-dev.2075
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/fp/flowAsync.d.mts +213 -0
- package/dist/fp/flowAsync.d.ts +213 -0
- package/dist/fp/flowAsync.js +37 -0
- package/dist/fp/flowAsync.mjs +37 -0
- package/dist/fp/index.d.mts +2 -1
- package/dist/fp/index.d.ts +2 -1
- package/dist/fp/index.js +2 -0
- package/dist/fp/index.mjs +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
//#region src/fp/flowAsync.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reusable async function from a single function.
|
|
4
|
+
*
|
|
5
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
6
|
+
* @returns An async function with the same parameters as `fn1` that resolves to its awaited result.
|
|
7
|
+
*/
|
|
8
|
+
declare function flowAsync<A extends any[], R1>(fn1: (...args: A) => R1): (...args: A) => Promise<Awaited<R1>>;
|
|
9
|
+
/**
|
|
10
|
+
* Composes `fn1` and `fn2` left-to-right into a single reusable async function, awaiting each result.
|
|
11
|
+
*
|
|
12
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
13
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
14
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn2`.
|
|
15
|
+
*/
|
|
16
|
+
declare function flowAsync<A extends any[], R1, R2>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2): (...args: A) => Promise<Awaited<R2>>;
|
|
17
|
+
/**
|
|
18
|
+
* Composes `fn1` through `fn3` left-to-right into a single reusable async function, awaiting each result.
|
|
19
|
+
*
|
|
20
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
21
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
22
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
23
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn3`.
|
|
24
|
+
*/
|
|
25
|
+
declare function flowAsync<A extends any[], R1, R2, R3>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3): (...args: A) => Promise<Awaited<R3>>;
|
|
26
|
+
/**
|
|
27
|
+
* Composes `fn1` through `fn4` left-to-right into a single reusable async function, awaiting each result.
|
|
28
|
+
*
|
|
29
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
30
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
31
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
32
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
33
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn4`.
|
|
34
|
+
*/
|
|
35
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4): (...args: A) => Promise<Awaited<R4>>;
|
|
36
|
+
/**
|
|
37
|
+
* Composes `fn1` through `fn5` left-to-right into a single reusable async function, awaiting each result.
|
|
38
|
+
*
|
|
39
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
40
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
41
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
42
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
43
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
44
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn5`.
|
|
45
|
+
*/
|
|
46
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5): (...args: A) => Promise<Awaited<R5>>;
|
|
47
|
+
/**
|
|
48
|
+
* Composes `fn1` through `fn6` left-to-right into a single reusable async function, awaiting each result.
|
|
49
|
+
*
|
|
50
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
51
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
52
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
53
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
54
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
55
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
56
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn6`.
|
|
57
|
+
*/
|
|
58
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6): (...args: A) => Promise<Awaited<R6>>;
|
|
59
|
+
/**
|
|
60
|
+
* Composes `fn1` through `fn7` left-to-right into a single reusable async function, awaiting each result.
|
|
61
|
+
*
|
|
62
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
63
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
64
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
65
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
66
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
67
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
68
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
69
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn7`.
|
|
70
|
+
*/
|
|
71
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7): (...args: A) => Promise<Awaited<R7>>;
|
|
72
|
+
/**
|
|
73
|
+
* Composes `fn1` through `fn8` left-to-right into a single reusable async function, awaiting each result.
|
|
74
|
+
*
|
|
75
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
76
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
77
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
78
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
79
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
80
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
81
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
82
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
83
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn8`.
|
|
84
|
+
*/
|
|
85
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8): (...args: A) => Promise<Awaited<R8>>;
|
|
86
|
+
/**
|
|
87
|
+
* Composes `fn1` through `fn9` left-to-right into a single reusable async function, awaiting each result.
|
|
88
|
+
*
|
|
89
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
90
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
91
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
92
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
93
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
94
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
95
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
96
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
97
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
98
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn9`.
|
|
99
|
+
*/
|
|
100
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9): (...args: A) => Promise<Awaited<R9>>;
|
|
101
|
+
/**
|
|
102
|
+
* Composes `fn1` through `fn10` left-to-right into a single reusable async function, awaiting each result.
|
|
103
|
+
*
|
|
104
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
105
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
106
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
107
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
108
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
109
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
110
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
111
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
112
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
113
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
114
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn10`.
|
|
115
|
+
*/
|
|
116
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10): (...args: A) => Promise<Awaited<R10>>;
|
|
117
|
+
/**
|
|
118
|
+
* Composes `fn1` through `fn11` left-to-right into a single reusable async function, awaiting each result.
|
|
119
|
+
*
|
|
120
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
121
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
122
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
123
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
124
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
125
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
126
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
127
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
128
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
129
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
130
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
131
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn11`.
|
|
132
|
+
*/
|
|
133
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11): (...args: A) => Promise<Awaited<R11>>;
|
|
134
|
+
/**
|
|
135
|
+
* Composes `fn1` through `fn12` left-to-right into a single reusable async function, awaiting each result.
|
|
136
|
+
*
|
|
137
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
138
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
139
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
140
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
141
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
142
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
143
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
144
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
145
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
146
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
147
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
148
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
149
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn12`.
|
|
150
|
+
*/
|
|
151
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12): (...args: A) => Promise<Awaited<R12>>;
|
|
152
|
+
/**
|
|
153
|
+
* Composes `fn1` through `fn13` left-to-right into a single reusable async function, awaiting each result.
|
|
154
|
+
*
|
|
155
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
156
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
157
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
158
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
159
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
160
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
161
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
162
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
163
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
164
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
165
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
166
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
167
|
+
* @param fn13 - Applied to the awaited result of `fn12`.
|
|
168
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn13`.
|
|
169
|
+
*/
|
|
170
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12, fn13: (input: Awaited<R12>) => R13): (...args: A) => Promise<Awaited<R13>>;
|
|
171
|
+
/**
|
|
172
|
+
* Composes `fn1` through `fn14` left-to-right into a single reusable async function, awaiting each result.
|
|
173
|
+
*
|
|
174
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
175
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
176
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
177
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
178
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
179
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
180
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
181
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
182
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
183
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
184
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
185
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
186
|
+
* @param fn13 - Applied to the awaited result of `fn12`.
|
|
187
|
+
* @param fn14 - Applied to the awaited result of `fn13`.
|
|
188
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn14`.
|
|
189
|
+
*/
|
|
190
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12, fn13: (input: Awaited<R12>) => R13, fn14: (input: Awaited<R13>) => R14): (...args: A) => Promise<Awaited<R14>>;
|
|
191
|
+
/**
|
|
192
|
+
* Composes `fn1` through `fn15` left-to-right into a single reusable async function, awaiting each result.
|
|
193
|
+
*
|
|
194
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
195
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
196
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
197
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
198
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
199
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
200
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
201
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
202
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
203
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
204
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
205
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
206
|
+
* @param fn13 - Applied to the awaited result of `fn12`.
|
|
207
|
+
* @param fn14 - Applied to the awaited result of `fn13`.
|
|
208
|
+
* @param fn15 - Applied to the awaited result of `fn14`.
|
|
209
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn15`.
|
|
210
|
+
*/
|
|
211
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12, fn13: (input: Awaited<R12>) => R13, fn14: (input: Awaited<R13>) => R14, fn15: (input: Awaited<R14>) => R15): (...args: A) => Promise<Awaited<R15>>;
|
|
212
|
+
//#endregion
|
|
213
|
+
export { flowAsync };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
//#region src/fp/flowAsync.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a reusable async function from a single function.
|
|
4
|
+
*
|
|
5
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
6
|
+
* @returns An async function with the same parameters as `fn1` that resolves to its awaited result.
|
|
7
|
+
*/
|
|
8
|
+
declare function flowAsync<A extends any[], R1>(fn1: (...args: A) => R1): (...args: A) => Promise<Awaited<R1>>;
|
|
9
|
+
/**
|
|
10
|
+
* Composes `fn1` and `fn2` left-to-right into a single reusable async function, awaiting each result.
|
|
11
|
+
*
|
|
12
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
13
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
14
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn2`.
|
|
15
|
+
*/
|
|
16
|
+
declare function flowAsync<A extends any[], R1, R2>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2): (...args: A) => Promise<Awaited<R2>>;
|
|
17
|
+
/**
|
|
18
|
+
* Composes `fn1` through `fn3` left-to-right into a single reusable async function, awaiting each result.
|
|
19
|
+
*
|
|
20
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
21
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
22
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
23
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn3`.
|
|
24
|
+
*/
|
|
25
|
+
declare function flowAsync<A extends any[], R1, R2, R3>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3): (...args: A) => Promise<Awaited<R3>>;
|
|
26
|
+
/**
|
|
27
|
+
* Composes `fn1` through `fn4` left-to-right into a single reusable async function, awaiting each result.
|
|
28
|
+
*
|
|
29
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
30
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
31
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
32
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
33
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn4`.
|
|
34
|
+
*/
|
|
35
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4): (...args: A) => Promise<Awaited<R4>>;
|
|
36
|
+
/**
|
|
37
|
+
* Composes `fn1` through `fn5` left-to-right into a single reusable async function, awaiting each result.
|
|
38
|
+
*
|
|
39
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
40
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
41
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
42
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
43
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
44
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn5`.
|
|
45
|
+
*/
|
|
46
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5): (...args: A) => Promise<Awaited<R5>>;
|
|
47
|
+
/**
|
|
48
|
+
* Composes `fn1` through `fn6` left-to-right into a single reusable async function, awaiting each result.
|
|
49
|
+
*
|
|
50
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
51
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
52
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
53
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
54
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
55
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
56
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn6`.
|
|
57
|
+
*/
|
|
58
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6): (...args: A) => Promise<Awaited<R6>>;
|
|
59
|
+
/**
|
|
60
|
+
* Composes `fn1` through `fn7` left-to-right into a single reusable async function, awaiting each result.
|
|
61
|
+
*
|
|
62
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
63
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
64
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
65
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
66
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
67
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
68
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
69
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn7`.
|
|
70
|
+
*/
|
|
71
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7): (...args: A) => Promise<Awaited<R7>>;
|
|
72
|
+
/**
|
|
73
|
+
* Composes `fn1` through `fn8` left-to-right into a single reusable async function, awaiting each result.
|
|
74
|
+
*
|
|
75
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
76
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
77
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
78
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
79
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
80
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
81
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
82
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
83
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn8`.
|
|
84
|
+
*/
|
|
85
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8): (...args: A) => Promise<Awaited<R8>>;
|
|
86
|
+
/**
|
|
87
|
+
* Composes `fn1` through `fn9` left-to-right into a single reusable async function, awaiting each result.
|
|
88
|
+
*
|
|
89
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
90
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
91
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
92
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
93
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
94
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
95
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
96
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
97
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
98
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn9`.
|
|
99
|
+
*/
|
|
100
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9): (...args: A) => Promise<Awaited<R9>>;
|
|
101
|
+
/**
|
|
102
|
+
* Composes `fn1` through `fn10` left-to-right into a single reusable async function, awaiting each result.
|
|
103
|
+
*
|
|
104
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
105
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
106
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
107
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
108
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
109
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
110
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
111
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
112
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
113
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
114
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn10`.
|
|
115
|
+
*/
|
|
116
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10): (...args: A) => Promise<Awaited<R10>>;
|
|
117
|
+
/**
|
|
118
|
+
* Composes `fn1` through `fn11` left-to-right into a single reusable async function, awaiting each result.
|
|
119
|
+
*
|
|
120
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
121
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
122
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
123
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
124
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
125
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
126
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
127
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
128
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
129
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
130
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
131
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn11`.
|
|
132
|
+
*/
|
|
133
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11): (...args: A) => Promise<Awaited<R11>>;
|
|
134
|
+
/**
|
|
135
|
+
* Composes `fn1` through `fn12` left-to-right into a single reusable async function, awaiting each result.
|
|
136
|
+
*
|
|
137
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
138
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
139
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
140
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
141
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
142
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
143
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
144
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
145
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
146
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
147
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
148
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
149
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn12`.
|
|
150
|
+
*/
|
|
151
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12): (...args: A) => Promise<Awaited<R12>>;
|
|
152
|
+
/**
|
|
153
|
+
* Composes `fn1` through `fn13` left-to-right into a single reusable async function, awaiting each result.
|
|
154
|
+
*
|
|
155
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
156
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
157
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
158
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
159
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
160
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
161
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
162
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
163
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
164
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
165
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
166
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
167
|
+
* @param fn13 - Applied to the awaited result of `fn12`.
|
|
168
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn13`.
|
|
169
|
+
*/
|
|
170
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12, fn13: (input: Awaited<R12>) => R13): (...args: A) => Promise<Awaited<R13>>;
|
|
171
|
+
/**
|
|
172
|
+
* Composes `fn1` through `fn14` left-to-right into a single reusable async function, awaiting each result.
|
|
173
|
+
*
|
|
174
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
175
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
176
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
177
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
178
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
179
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
180
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
181
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
182
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
183
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
184
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
185
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
186
|
+
* @param fn13 - Applied to the awaited result of `fn12`.
|
|
187
|
+
* @param fn14 - Applied to the awaited result of `fn13`.
|
|
188
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn14`.
|
|
189
|
+
*/
|
|
190
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12, fn13: (input: Awaited<R12>) => R13, fn14: (input: Awaited<R13>) => R14): (...args: A) => Promise<Awaited<R14>>;
|
|
191
|
+
/**
|
|
192
|
+
* Composes `fn1` through `fn15` left-to-right into a single reusable async function, awaiting each result.
|
|
193
|
+
*
|
|
194
|
+
* @param fn1 - The first function, which may take any number of arguments.
|
|
195
|
+
* @param fn2 - Applied to the awaited result of `fn1`.
|
|
196
|
+
* @param fn3 - Applied to the awaited result of `fn2`.
|
|
197
|
+
* @param fn4 - Applied to the awaited result of `fn3`.
|
|
198
|
+
* @param fn5 - Applied to the awaited result of `fn4`.
|
|
199
|
+
* @param fn6 - Applied to the awaited result of `fn5`.
|
|
200
|
+
* @param fn7 - Applied to the awaited result of `fn6`.
|
|
201
|
+
* @param fn8 - Applied to the awaited result of `fn7`.
|
|
202
|
+
* @param fn9 - Applied to the awaited result of `fn8`.
|
|
203
|
+
* @param fn10 - Applied to the awaited result of `fn9`.
|
|
204
|
+
* @param fn11 - Applied to the awaited result of `fn10`.
|
|
205
|
+
* @param fn12 - Applied to the awaited result of `fn11`.
|
|
206
|
+
* @param fn13 - Applied to the awaited result of `fn12`.
|
|
207
|
+
* @param fn14 - Applied to the awaited result of `fn13`.
|
|
208
|
+
* @param fn15 - Applied to the awaited result of `fn14`.
|
|
209
|
+
* @returns An async function with the same parameters as `fn1` that resolves to the awaited result of `fn15`.
|
|
210
|
+
*/
|
|
211
|
+
declare function flowAsync<A extends any[], R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15>(fn1: (...args: A) => R1, fn2: (input: Awaited<R1>) => R2, fn3: (input: Awaited<R2>) => R3, fn4: (input: Awaited<R3>) => R4, fn5: (input: Awaited<R4>) => R5, fn6: (input: Awaited<R5>) => R6, fn7: (input: Awaited<R6>) => R7, fn8: (input: Awaited<R7>) => R8, fn9: (input: Awaited<R8>) => R9, fn10: (input: Awaited<R9>) => R10, fn11: (input: Awaited<R10>) => R11, fn12: (input: Awaited<R11>) => R12, fn13: (input: Awaited<R12>) => R13, fn14: (input: Awaited<R13>) => R14, fn15: (input: Awaited<R14>) => R15): (...args: A) => Promise<Awaited<R15>>;
|
|
212
|
+
//#endregion
|
|
213
|
+
export { flowAsync };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/fp/flowAsync.ts
|
|
2
|
+
/**
|
|
3
|
+
* Performs left-to-right async function composition, returning a **reusable
|
|
4
|
+
* async function** instead of running immediately. The first function may take
|
|
5
|
+
* any number of arguments; every later function is unary and receives the
|
|
6
|
+
* awaited result of the previous one.
|
|
7
|
+
*
|
|
8
|
+
* `flowAsync` is the promise-aware sibling of {@link flow}: where `flow` passes
|
|
9
|
+
* each raw return value straight to the next function (so a returned `Promise`
|
|
10
|
+
* arrives unresolved), `flowAsync` awaits every step, letting synchronous and
|
|
11
|
+
* asynchronous functions mix freely in one chain. The composed function always
|
|
12
|
+
* returns a `Promise`.
|
|
13
|
+
*
|
|
14
|
+
* @param functions - The functions to compose. The first may be variadic; the
|
|
15
|
+
* rest are unary, each receiving the awaited output of the previous function.
|
|
16
|
+
* @returns An async function that, when called, applies every function
|
|
17
|
+
* left-to-right, awaiting each result.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { flowAsync } from 'es-toolkit/fp';
|
|
21
|
+
*
|
|
22
|
+
* const fetchUser = async (id: number) => ({ id, name: 'Alice' });
|
|
23
|
+
* const getName = (user: { name: string }) => user.name;
|
|
24
|
+
*
|
|
25
|
+
* const getUserName = flowAsync(fetchUser, getName);
|
|
26
|
+
* await getUserName(1); // => 'Alice'
|
|
27
|
+
*/
|
|
28
|
+
function flowAsync(...functions) {
|
|
29
|
+
return async function(...args) {
|
|
30
|
+
if (functions.length === 0) return args[0];
|
|
31
|
+
let result = await functions[0].apply(this, args);
|
|
32
|
+
for (let i = 1; i < functions.length; i++) result = await functions[i].call(this, result);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.flowAsync = flowAsync;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/fp/flowAsync.ts
|
|
2
|
+
/**
|
|
3
|
+
* Performs left-to-right async function composition, returning a **reusable
|
|
4
|
+
* async function** instead of running immediately. The first function may take
|
|
5
|
+
* any number of arguments; every later function is unary and receives the
|
|
6
|
+
* awaited result of the previous one.
|
|
7
|
+
*
|
|
8
|
+
* `flowAsync` is the promise-aware sibling of {@link flow}: where `flow` passes
|
|
9
|
+
* each raw return value straight to the next function (so a returned `Promise`
|
|
10
|
+
* arrives unresolved), `flowAsync` awaits every step, letting synchronous and
|
|
11
|
+
* asynchronous functions mix freely in one chain. The composed function always
|
|
12
|
+
* returns a `Promise`.
|
|
13
|
+
*
|
|
14
|
+
* @param functions - The functions to compose. The first may be variadic; the
|
|
15
|
+
* rest are unary, each receiving the awaited output of the previous function.
|
|
16
|
+
* @returns An async function that, when called, applies every function
|
|
17
|
+
* left-to-right, awaiting each result.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { flowAsync } from 'es-toolkit/fp';
|
|
21
|
+
*
|
|
22
|
+
* const fetchUser = async (id: number) => ({ id, name: 'Alice' });
|
|
23
|
+
* const getName = (user: { name: string }) => user.name;
|
|
24
|
+
*
|
|
25
|
+
* const getUserName = flowAsync(fetchUser, getName);
|
|
26
|
+
* await getUserName(1); // => 'Alice'
|
|
27
|
+
*/
|
|
28
|
+
function flowAsync(...functions) {
|
|
29
|
+
return async function(...args) {
|
|
30
|
+
if (functions.length === 0) return args[0];
|
|
31
|
+
let result = await functions[0].apply(this, args);
|
|
32
|
+
for (let i = 1; i < functions.length; i++) result = await functions[i].call(this, result);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { flowAsync };
|
package/dist/fp/index.d.mts
CHANGED
|
@@ -68,9 +68,10 @@ import { zip } from "./array/zip.mjs";
|
|
|
68
68
|
import { zipObject } from "./array/zipObject.mjs";
|
|
69
69
|
import { zipWith } from "./array/zipWith.mjs";
|
|
70
70
|
import { flow } from "./flow.mjs";
|
|
71
|
+
import { flowAsync } from "./flowAsync.mjs";
|
|
71
72
|
import { add } from "./math/add.mjs";
|
|
72
73
|
import { multiply } from "./math/multiply.mjs";
|
|
73
74
|
import { omit } from "./object/omit.mjs";
|
|
74
75
|
import { pick } from "./object/pick.mjs";
|
|
75
76
|
import { pipe } from "./pipe.mjs";
|
|
76
|
-
export { WindowedOptions, add, at, cartesianProduct, chunk, chunkBy, combinations, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, filter, find, findIndex, findLast, findLastIndex, flatMap, flatMapDeep, flatten, flattenDeep, flow, forEach, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, join, keyBy, last, length, map, maxBy, minBy, multiply, omit, orderBy, partition, pick, pipe, reverse, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
77
|
+
export { WindowedOptions, add, at, cartesianProduct, chunk, chunkBy, combinations, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, filter, find, findIndex, findLast, findLastIndex, flatMap, flatMapDeep, flatten, flattenDeep, flow, flowAsync, forEach, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, join, keyBy, last, length, map, maxBy, minBy, multiply, omit, orderBy, partition, pick, pipe, reverse, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/fp/index.d.ts
CHANGED
|
@@ -68,9 +68,10 @@ import { zip } from "./array/zip.js";
|
|
|
68
68
|
import { zipObject } from "./array/zipObject.js";
|
|
69
69
|
import { zipWith } from "./array/zipWith.js";
|
|
70
70
|
import { flow } from "./flow.js";
|
|
71
|
+
import { flowAsync } from "./flowAsync.js";
|
|
71
72
|
import { add } from "./math/add.js";
|
|
72
73
|
import { multiply } from "./math/multiply.js";
|
|
73
74
|
import { omit } from "./object/omit.js";
|
|
74
75
|
import { pick } from "./object/pick.js";
|
|
75
76
|
import { pipe } from "./pipe.js";
|
|
76
|
-
export { WindowedOptions, add, at, cartesianProduct, chunk, chunkBy, combinations, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, filter, find, findIndex, findLast, findLastIndex, flatMap, flatMapDeep, flatten, flattenDeep, flow, forEach, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, join, keyBy, last, length, map, maxBy, minBy, multiply, omit, orderBy, partition, pick, pipe, reverse, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
77
|
+
export { WindowedOptions, add, at, cartesianProduct, chunk, chunkBy, combinations, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, filter, find, findIndex, findLast, findLastIndex, flatMap, flatMapDeep, flatten, flattenDeep, flow, flowAsync, forEach, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, join, keyBy, last, length, map, maxBy, minBy, multiply, omit, orderBy, partition, pick, pipe, reverse, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/fp/index.js
CHANGED
|
@@ -70,6 +70,7 @@ const require_zipWith = require("./array/zipWith.js");
|
|
|
70
70
|
require("./array/index.js");
|
|
71
71
|
const require_pipe = require("./pipe.js");
|
|
72
72
|
const require_flow = require("./flow.js");
|
|
73
|
+
const require_flowAsync = require("./flowAsync.js");
|
|
73
74
|
const require_add = require("./math/add.js");
|
|
74
75
|
const require_multiply = require("./math/multiply.js");
|
|
75
76
|
require("./math/index.js");
|
|
@@ -101,6 +102,7 @@ exports.flatMapDeep = require_flatMapDeep.flatMapDeep;
|
|
|
101
102
|
exports.flatten = require_flatten.flatten;
|
|
102
103
|
exports.flattenDeep = require_flattenDeep.flattenDeep;
|
|
103
104
|
exports.flow = require_flow.flow;
|
|
105
|
+
exports.flowAsync = require_flowAsync.flowAsync;
|
|
104
106
|
exports.forEach = require_forEach.forEach;
|
|
105
107
|
exports.groupBy = require_groupBy.groupBy;
|
|
106
108
|
exports.head = require_head.head;
|
package/dist/fp/index.mjs
CHANGED
|
@@ -69,10 +69,11 @@ import { zipWith } from "./array/zipWith.mjs";
|
|
|
69
69
|
import "./array/index.mjs";
|
|
70
70
|
import { pipe } from "./pipe.mjs";
|
|
71
71
|
import { flow } from "./flow.mjs";
|
|
72
|
+
import { flowAsync } from "./flowAsync.mjs";
|
|
72
73
|
import { add } from "./math/add.mjs";
|
|
73
74
|
import { multiply } from "./math/multiply.mjs";
|
|
74
75
|
import "./math/index.mjs";
|
|
75
76
|
import { omit } from "./object/omit.mjs";
|
|
76
77
|
import { pick } from "./object/pick.mjs";
|
|
77
78
|
import "./object/index.mjs";
|
|
78
|
-
export { add, at, cartesianProduct, chunk, chunkBy, combinations, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, filter, find, findIndex, findLast, findLastIndex, flatMap, flatMapDeep, flatten, flattenDeep, flow, forEach, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, join, keyBy, last, length, map, maxBy, minBy, multiply, omit, orderBy, partition, pick, pipe, reverse, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
79
|
+
export { add, at, cartesianProduct, chunk, chunkBy, combinations, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, filter, find, findIndex, findLast, findLastIndex, flatMap, flatMapDeep, flatten, flattenDeep, flow, flowAsync, forEach, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, join, keyBy, last, length, map, maxBy, minBy, multiply, omit, orderBy, partition, pick, pipe, reverse, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.51.0-dev.
|
|
3
|
+
"version": "1.51.0-dev.2075+9f898eb9",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|