@oscarpalmer/atoms 0.147.0 → 0.149.0
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/atoms.full.js +114 -32
- package/dist/function/work.js +29 -10
- package/dist/index.js +2 -1
- package/dist/internal/result.js +25 -0
- package/dist/{result.js → result/index.js} +8 -25
- package/dist/result/match.js +25 -0
- package/dist/result/models.js +0 -0
- package/dist/result/work/flow.js +25 -0
- package/dist/result/work/pipe.js +21 -0
- package/package.json +3 -3
- package/src/function/work.ts +316 -254
- package/src/index.ts +1 -1
- package/src/internal/result.ts +80 -0
- package/src/{result.ts → result/index.ts} +17 -114
- package/src/result/match.ts +112 -0
- package/src/result/models.ts +81 -0
- package/src/result/work/flow.ts +433 -0
- package/src/result/work/pipe.ts +791 -0
- package/types/function/work.d.ts +51 -50
- package/types/index.d.ts +1 -1
- package/types/internal/result.d.ts +37 -0
- package/types/{result.d.ts → result/index.d.ts} +11 -67
- package/types/result/match.d.ts +31 -0
- package/types/result/models.d.ts +60 -0
- package/types/result/work/flow.d.ts +134 -0
- package/types/result/work/pipe.d.ts +271 -0
package/src/function/work.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import {isError, isOk} from '../internal/result';
|
|
1
2
|
import type {GenericCallback} from '../models';
|
|
3
|
+
import type {UnwrapValue} from '../result/models';
|
|
2
4
|
import {assert, type Asserter} from './assert';
|
|
3
5
|
|
|
4
6
|
// #region Types
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
|
-
* A synchronous Flow, a function that
|
|
9
|
+
* A synchronous Flow, a function that pipe a value through a series of functions
|
|
8
10
|
*/
|
|
9
|
-
export type Flow<Callback extends GenericCallback, Value =
|
|
11
|
+
export type Flow<Callback extends GenericCallback, Value> = (
|
|
10
12
|
...args: Parameters<Callback>
|
|
11
|
-
) => Value
|
|
13
|
+
) => UnwrapValue<Value>;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
|
-
* An asynchronous Flow, a function that pipes
|
|
16
|
+
* An asynchronous Flow, a function that pipes a value through a series of functions
|
|
15
17
|
*/
|
|
16
|
-
export type FlowPromise<Callback extends GenericCallback, Value =
|
|
18
|
+
export type FlowPromise<Callback extends GenericCallback, Value> = (
|
|
17
19
|
...args: Parameters<Callback>
|
|
18
|
-
) => Promise<
|
|
20
|
+
) => Promise<UnwrapValue<Value>>;
|
|
19
21
|
|
|
20
22
|
// #endregion
|
|
21
23
|
|
|
@@ -29,7 +31,7 @@ export type FlowPromise<Callback extends GenericCallback, Value = ReturnType<Cal
|
|
|
29
31
|
* Create an asynchronous Flow, a function that pipes values through a function
|
|
30
32
|
* @returns Flow function
|
|
31
33
|
*/
|
|
32
|
-
function asyncFlow<Fn extends GenericCallback>(fn: Fn): FlowPromise<Fn
|
|
34
|
+
function asyncFlow<Fn extends GenericCallback>(fn: Fn): FlowPromise<Fn, ReturnType<Fn>>;
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
37
|
* Create an asynchronous Flow, a function that pipes values through a series of functions
|
|
@@ -37,7 +39,7 @@ function asyncFlow<Fn extends GenericCallback>(fn: Fn): FlowPromise<Fn>;
|
|
|
37
39
|
*/
|
|
38
40
|
function asyncFlow<First extends GenericCallback, Second>(
|
|
39
41
|
first: First,
|
|
40
|
-
second: (value: Awaited<ReturnType<First
|
|
42
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
41
43
|
): FlowPromise<First, Second>;
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -46,8 +48,8 @@ function asyncFlow<First extends GenericCallback, Second>(
|
|
|
46
48
|
*/
|
|
47
49
|
function asyncFlow<First extends GenericCallback, Second, Third>(
|
|
48
50
|
first: First,
|
|
49
|
-
second: (value: Awaited<ReturnType<First
|
|
50
|
-
third: (value: Awaited<Second
|
|
51
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
52
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
51
53
|
): FlowPromise<First, Third>;
|
|
52
54
|
|
|
53
55
|
/**
|
|
@@ -56,9 +58,9 @@ function asyncFlow<First extends GenericCallback, Second, Third>(
|
|
|
56
58
|
*/
|
|
57
59
|
function asyncFlow<First extends GenericCallback, Second, Third, Fourth>(
|
|
58
60
|
first: First,
|
|
59
|
-
second: (value: Awaited<ReturnType<First
|
|
60
|
-
third: (value: Awaited<Second
|
|
61
|
-
fourth: (value: Awaited<Third
|
|
61
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
62
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
63
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
62
64
|
): FlowPromise<First, Fourth>;
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -67,10 +69,10 @@ function asyncFlow<First extends GenericCallback, Second, Third, Fourth>(
|
|
|
67
69
|
*/
|
|
68
70
|
function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(
|
|
69
71
|
first: First,
|
|
70
|
-
second: (value: Awaited<ReturnType<First
|
|
71
|
-
third: (value: Awaited<Second
|
|
72
|
-
fourth: (value: Awaited<Third
|
|
73
|
-
fifth: (value: Awaited<Fourth
|
|
72
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
73
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
74
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
75
|
+
fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
|
|
74
76
|
): FlowPromise<First, Fifth>;
|
|
75
77
|
|
|
76
78
|
/**
|
|
@@ -79,11 +81,11 @@ function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(
|
|
|
79
81
|
*/
|
|
80
82
|
function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(
|
|
81
83
|
first: First,
|
|
82
|
-
second: (value: Awaited<ReturnType<First
|
|
83
|
-
third: (value: Awaited<Second
|
|
84
|
-
fourth: (value: Awaited<Third
|
|
85
|
-
fifth: (value: Awaited<Fourth
|
|
86
|
-
sixth: (value: Awaited<Fifth
|
|
84
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
85
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
86
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
87
|
+
fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
|
|
88
|
+
sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
|
|
87
89
|
): FlowPromise<First, Sixth>;
|
|
88
90
|
|
|
89
91
|
/**
|
|
@@ -92,12 +94,12 @@ function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth,
|
|
|
92
94
|
*/
|
|
93
95
|
function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
94
96
|
first: First,
|
|
95
|
-
second: (value: Awaited<ReturnType<First
|
|
96
|
-
third: (value: Awaited<Second
|
|
97
|
-
fourth: (value: Awaited<Third
|
|
98
|
-
fifth: (value: Awaited<Fourth
|
|
99
|
-
sixth: (value: Awaited<Fifth
|
|
100
|
-
seventh: (value: Awaited<Sixth
|
|
97
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
98
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
99
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
100
|
+
fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
|
|
101
|
+
sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
|
|
102
|
+
seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
|
|
101
103
|
): FlowPromise<First, Seventh>;
|
|
102
104
|
|
|
103
105
|
/**
|
|
@@ -115,13 +117,13 @@ function asyncFlow<
|
|
|
115
117
|
Eighth,
|
|
116
118
|
>(
|
|
117
119
|
first: First,
|
|
118
|
-
second: (value: Awaited<ReturnType<First
|
|
119
|
-
third: (value: Awaited<Second
|
|
120
|
-
fourth: (value: Awaited<Third
|
|
121
|
-
fifth: (value: Awaited<Fourth
|
|
122
|
-
sixth: (value: Awaited<Fifth
|
|
123
|
-
seventh: (value: Awaited<Sixth
|
|
124
|
-
eighth: (value: Awaited<Seventh
|
|
120
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
121
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
122
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
123
|
+
fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
|
|
124
|
+
sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
|
|
125
|
+
seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
|
|
126
|
+
eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth,
|
|
125
127
|
): FlowPromise<First, Eighth>;
|
|
126
128
|
|
|
127
129
|
/**
|
|
@@ -140,14 +142,14 @@ function asyncFlow<
|
|
|
140
142
|
Ninth,
|
|
141
143
|
>(
|
|
142
144
|
first: First,
|
|
143
|
-
second: (value: Awaited<ReturnType<First
|
|
144
|
-
third: (value: Awaited<Second
|
|
145
|
-
fourth: (value: Awaited<Third
|
|
146
|
-
fifth: (value: Awaited<Fourth
|
|
147
|
-
sixth: (value: Awaited<Fifth
|
|
148
|
-
seventh: (value: Awaited<Sixth
|
|
149
|
-
eighth: (value: Awaited<Seventh
|
|
150
|
-
ninth: (value: Awaited<Eighth
|
|
145
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
146
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
147
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
148
|
+
fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
|
|
149
|
+
sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
|
|
150
|
+
seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
|
|
151
|
+
eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth,
|
|
152
|
+
ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth,
|
|
151
153
|
): FlowPromise<First, Ninth>;
|
|
152
154
|
|
|
153
155
|
/**
|
|
@@ -167,15 +169,15 @@ function asyncFlow<
|
|
|
167
169
|
Tenth,
|
|
168
170
|
>(
|
|
169
171
|
first: First,
|
|
170
|
-
second: (value: Awaited<ReturnType<First
|
|
171
|
-
third: (value: Awaited<Second
|
|
172
|
-
fourth: (value: Awaited<Third
|
|
173
|
-
fifth: (value: Awaited<Fourth
|
|
174
|
-
sixth: (value: Awaited<Fifth
|
|
175
|
-
seventh: (value: Awaited<Sixth
|
|
176
|
-
eighth: (value: Awaited<Seventh
|
|
177
|
-
ninth: (value: Awaited<Eighth
|
|
178
|
-
tenth: (value: Awaited<Ninth
|
|
172
|
+
second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second,
|
|
173
|
+
third: (value: Awaited<UnwrapValue<Second>>) => Third,
|
|
174
|
+
fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth,
|
|
175
|
+
fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth,
|
|
176
|
+
sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth,
|
|
177
|
+
seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh,
|
|
178
|
+
eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth,
|
|
179
|
+
ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth,
|
|
180
|
+
tenth: (value: Awaited<UnwrapValue<Ninth>>) => Tenth,
|
|
179
181
|
): FlowPromise<First, Tenth>;
|
|
180
182
|
|
|
181
183
|
/**
|
|
@@ -184,19 +186,30 @@ function asyncFlow<
|
|
|
184
186
|
*/
|
|
185
187
|
function asyncFlow<Fn extends GenericCallback>(
|
|
186
188
|
fn: Fn,
|
|
187
|
-
...fns: Array<(value: Awaited<ReturnType<Fn
|
|
188
|
-
): FlowPromise<Fn
|
|
189
|
+
...fns: Array<(value: Awaited<UnwrapValue<ReturnType<Fn>>>) => unknown>
|
|
190
|
+
): FlowPromise<Fn, ReturnType<Fn>>;
|
|
189
191
|
|
|
190
192
|
/**
|
|
191
193
|
* Create an asynchronous Flow, a function that pipes values through a series of functions
|
|
192
194
|
* @returns Flow function
|
|
193
195
|
*/
|
|
194
|
-
function asyncFlow(...fns:
|
|
196
|
+
function asyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise<unknown>;
|
|
195
197
|
|
|
196
|
-
function asyncFlow(...fns:
|
|
198
|
+
function asyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise<unknown> {
|
|
197
199
|
assertFlowFunctions(fns);
|
|
198
200
|
|
|
199
|
-
return (...args: unknown[]): Promise<unknown> =>
|
|
201
|
+
return (...args: unknown[]): Promise<unknown> =>
|
|
202
|
+
asyncWork(
|
|
203
|
+
args.map(value => {
|
|
204
|
+
if (isError(value)) {
|
|
205
|
+
throw value.error;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return isOk(value) ? value.value : value;
|
|
209
|
+
}),
|
|
210
|
+
fns,
|
|
211
|
+
true,
|
|
212
|
+
);
|
|
200
213
|
}
|
|
201
214
|
|
|
202
215
|
// #endregion
|
|
@@ -207,7 +220,7 @@ function asyncFlow(...fns: Function[]): (...args: unknown[]) => Promise<unknown>
|
|
|
207
220
|
* Create a Flow, a function that pipes values through a function
|
|
208
221
|
* @returns Flow function
|
|
209
222
|
*/
|
|
210
|
-
export function flow<Fn extends GenericCallback>(fn: Fn): Flow<Fn
|
|
223
|
+
export function flow<Fn extends GenericCallback>(fn: Fn): Flow<Fn, ReturnType<Fn>>;
|
|
211
224
|
|
|
212
225
|
/**
|
|
213
226
|
* Create a Flow, a function that pipes values through a series of functions
|
|
@@ -215,7 +228,7 @@ export function flow<Fn extends GenericCallback>(fn: Fn): Flow<Fn>;
|
|
|
215
228
|
*/
|
|
216
229
|
export function flow<First extends GenericCallback, Second>(
|
|
217
230
|
first: First,
|
|
218
|
-
second: (value: ReturnType<First
|
|
231
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
219
232
|
): Flow<First, Second>;
|
|
220
233
|
|
|
221
234
|
/**
|
|
@@ -224,8 +237,8 @@ export function flow<First extends GenericCallback, Second>(
|
|
|
224
237
|
*/
|
|
225
238
|
export function flow<First extends GenericCallback, Second, Third>(
|
|
226
239
|
first: First,
|
|
227
|
-
second: (value: ReturnType<First
|
|
228
|
-
third: (value: Second) => Third,
|
|
240
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
241
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
229
242
|
): Flow<First, Third>;
|
|
230
243
|
|
|
231
244
|
/**
|
|
@@ -234,9 +247,9 @@ export function flow<First extends GenericCallback, Second, Third>(
|
|
|
234
247
|
*/
|
|
235
248
|
export function flow<First extends GenericCallback, Second, Third, Fourth>(
|
|
236
249
|
first: First,
|
|
237
|
-
second: (value: ReturnType<First
|
|
238
|
-
third: (value: Second) => Third,
|
|
239
|
-
fourth: (value: Third) => Fourth,
|
|
250
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
251
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
252
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
240
253
|
): Flow<First, Fourth>;
|
|
241
254
|
|
|
242
255
|
/**
|
|
@@ -245,10 +258,10 @@ export function flow<First extends GenericCallback, Second, Third, Fourth>(
|
|
|
245
258
|
*/
|
|
246
259
|
export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth>(
|
|
247
260
|
first: First,
|
|
248
|
-
second: (value: ReturnType<First
|
|
249
|
-
third: (value: Second) => Third,
|
|
250
|
-
fourth: (value: Third) => Fourth,
|
|
251
|
-
fifth: (value: Fourth) => Fifth,
|
|
261
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
262
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
263
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
264
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
252
265
|
): Flow<First, Fifth>;
|
|
253
266
|
|
|
254
267
|
/**
|
|
@@ -257,11 +270,11 @@ export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth
|
|
|
257
270
|
*/
|
|
258
271
|
export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(
|
|
259
272
|
first: First,
|
|
260
|
-
second: (value: ReturnType<First
|
|
261
|
-
third: (value: Second) => Third,
|
|
262
|
-
fourth: (value: Third) => Fourth,
|
|
263
|
-
fifth: (value: Fourth) => Fifth,
|
|
264
|
-
sixth: (value: Fifth) => Sixth,
|
|
273
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
274
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
275
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
276
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
277
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
265
278
|
): Flow<First, Sixth>;
|
|
266
279
|
|
|
267
280
|
/**
|
|
@@ -270,12 +283,12 @@ export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth
|
|
|
270
283
|
*/
|
|
271
284
|
export function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
272
285
|
first: First,
|
|
273
|
-
second: (value: ReturnType<First
|
|
274
|
-
third: (value: Second) => Third,
|
|
275
|
-
fourth: (value: Third) => Fourth,
|
|
276
|
-
fifth: (value: Fourth) => Fifth,
|
|
277
|
-
sixth: (value: Fifth) => Sixth,
|
|
278
|
-
seventh: (value: Sixth) => Seventh,
|
|
286
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
287
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
288
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
289
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
290
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
291
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
279
292
|
): Flow<First, Seventh>;
|
|
280
293
|
|
|
281
294
|
/**
|
|
@@ -293,13 +306,13 @@ export function flow<
|
|
|
293
306
|
Eighth,
|
|
294
307
|
>(
|
|
295
308
|
first: First,
|
|
296
|
-
second: (value: ReturnType<First
|
|
297
|
-
third: (value: Second) => Third,
|
|
298
|
-
fourth: (value: Third) => Fourth,
|
|
299
|
-
fifth: (value: Fourth) => Fifth,
|
|
300
|
-
sixth: (value: Fifth) => Sixth,
|
|
301
|
-
seventh: (value: Sixth) => Seventh,
|
|
302
|
-
eighth: (value: Seventh) => Eighth,
|
|
309
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
310
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
311
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
312
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
313
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
314
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
315
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
303
316
|
): Flow<First, Eighth>;
|
|
304
317
|
|
|
305
318
|
/**
|
|
@@ -318,14 +331,14 @@ export function flow<
|
|
|
318
331
|
Ninth,
|
|
319
332
|
>(
|
|
320
333
|
first: First,
|
|
321
|
-
second: (value: ReturnType<First
|
|
322
|
-
third: (value: Second) => Third,
|
|
323
|
-
fourth: (value: Third) => Fourth,
|
|
324
|
-
fifth: (value: Fourth) => Fifth,
|
|
325
|
-
sixth: (value: Fifth) => Sixth,
|
|
326
|
-
seventh: (value: Sixth) => Seventh,
|
|
327
|
-
eighth: (value: Seventh) => Eighth,
|
|
328
|
-
ninth: (value: Eighth) => Ninth,
|
|
334
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
335
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
336
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
337
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
338
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
339
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
340
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
341
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
329
342
|
): Flow<First, Ninth>;
|
|
330
343
|
|
|
331
344
|
/**
|
|
@@ -345,15 +358,15 @@ export function flow<
|
|
|
345
358
|
Tenth,
|
|
346
359
|
>(
|
|
347
360
|
first: First,
|
|
348
|
-
second: (value: ReturnType<First
|
|
349
|
-
third: (value: Second) => Third,
|
|
350
|
-
fourth: (value: Third) => Fourth,
|
|
351
|
-
fifth: (value: Fourth) => Fifth,
|
|
352
|
-
sixth: (value: Fifth) => Sixth,
|
|
353
|
-
seventh: (value: Sixth) => Seventh,
|
|
354
|
-
eighth: (value: Seventh) => Eighth,
|
|
355
|
-
ninth: (value: Eighth) => Ninth,
|
|
356
|
-
tenth: (value: Ninth) => Tenth,
|
|
361
|
+
second: (value: UnwrapValue<ReturnType<First>>) => Second,
|
|
362
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
363
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
364
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
365
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
366
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
367
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
368
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
369
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
357
370
|
): Flow<First, Tenth>;
|
|
358
371
|
|
|
359
372
|
/**
|
|
@@ -362,19 +375,30 @@ export function flow<
|
|
|
362
375
|
*/
|
|
363
376
|
export function flow<First extends GenericCallback>(
|
|
364
377
|
first: First,
|
|
365
|
-
...fns: Array<(value: ReturnType<First
|
|
366
|
-
): Flow<First
|
|
378
|
+
...fns: Array<(value: UnwrapValue<ReturnType<First>>) => unknown>
|
|
379
|
+
): Flow<First, ReturnType<First>>;
|
|
367
380
|
|
|
368
381
|
/**
|
|
369
382
|
* Create a Flow, a function that pipes values through a series of functions
|
|
370
383
|
* @returns Flow function
|
|
371
384
|
*/
|
|
372
|
-
export function flow(...fns:
|
|
385
|
+
export function flow(...fns: GenericCallback[]): (...args: unknown[]) => unknown;
|
|
373
386
|
|
|
374
|
-
export function flow(...fns:
|
|
387
|
+
export function flow(...fns: GenericCallback[]): (...args: unknown[]) => unknown {
|
|
375
388
|
assertFlowFunctions(fns);
|
|
376
389
|
|
|
377
|
-
return (...args: unknown[]): unknown =>
|
|
390
|
+
return (...args: unknown[]): unknown =>
|
|
391
|
+
work(
|
|
392
|
+
args.map(value => {
|
|
393
|
+
if (isError(value)) {
|
|
394
|
+
throw value.error;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return isOk(value) ? value.value : value;
|
|
398
|
+
}),
|
|
399
|
+
fns,
|
|
400
|
+
true,
|
|
401
|
+
);
|
|
378
402
|
}
|
|
379
403
|
|
|
380
404
|
flow.async = asyncFlow;
|
|
@@ -392,10 +416,10 @@ flow.async = asyncFlow;
|
|
|
392
416
|
* @param value Initial value
|
|
393
417
|
* @returns Piped result
|
|
394
418
|
*/
|
|
395
|
-
async function asyncPipe<Initial,
|
|
419
|
+
async function asyncPipe<Initial, Piped>(
|
|
396
420
|
value: Initial,
|
|
397
|
-
pipe: (value: Initial) =>
|
|
398
|
-
): Promise<
|
|
421
|
+
pipe: (value: UnwrapValue<Initial>) => Piped,
|
|
422
|
+
): Promise<UnwrapValue<Piped>>;
|
|
399
423
|
|
|
400
424
|
/**
|
|
401
425
|
* Pipe a value through a series of functions
|
|
@@ -404,9 +428,9 @@ async function asyncPipe<Initial, Pipe>(
|
|
|
404
428
|
*/
|
|
405
429
|
async function asyncPipe<Initial, First, Second>(
|
|
406
430
|
value: Initial,
|
|
407
|
-
first: (value: Initial) => First,
|
|
408
|
-
second: (value:
|
|
409
|
-
): Promise<
|
|
431
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
432
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
433
|
+
): Promise<UnwrapValue<Second>>;
|
|
410
434
|
|
|
411
435
|
/**
|
|
412
436
|
* Pipe a value through a series of functions
|
|
@@ -415,10 +439,10 @@ async function asyncPipe<Initial, First, Second>(
|
|
|
415
439
|
*/
|
|
416
440
|
async function asyncPipe<Initial, First, Second, Third>(
|
|
417
441
|
value: Initial,
|
|
418
|
-
first: (value: Initial) => First,
|
|
419
|
-
second: (value:
|
|
420
|
-
third: (value:
|
|
421
|
-
): Promise<
|
|
442
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
443
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
444
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
445
|
+
): Promise<UnwrapValue<Third>>;
|
|
422
446
|
|
|
423
447
|
/**
|
|
424
448
|
* Pipe a value through a series of functions
|
|
@@ -427,11 +451,11 @@ async function asyncPipe<Initial, First, Second, Third>(
|
|
|
427
451
|
*/
|
|
428
452
|
async function asyncPipe<Initial, First, Second, Third, Fourth>(
|
|
429
453
|
value: Initial,
|
|
430
|
-
first: (value: Initial) => First,
|
|
431
|
-
second: (value:
|
|
432
|
-
third: (value:
|
|
433
|
-
fourth: (value:
|
|
434
|
-
): Promise<
|
|
454
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
455
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
456
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
457
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
458
|
+
): Promise<UnwrapValue<Fourth>>;
|
|
435
459
|
|
|
436
460
|
/**
|
|
437
461
|
* Pipe a value through a series of functions
|
|
@@ -440,12 +464,12 @@ async function asyncPipe<Initial, First, Second, Third, Fourth>(
|
|
|
440
464
|
*/
|
|
441
465
|
async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
442
466
|
value: Initial,
|
|
443
|
-
first: (value: Initial) => First,
|
|
444
|
-
second: (value:
|
|
445
|
-
third: (value:
|
|
446
|
-
fourth: (value:
|
|
447
|
-
fifth: (value:
|
|
448
|
-
): Promise<
|
|
467
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
468
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
469
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
470
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
471
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
472
|
+
): Promise<UnwrapValue<Fifth>>;
|
|
449
473
|
|
|
450
474
|
/**
|
|
451
475
|
* Pipe a value through a series of functions
|
|
@@ -454,13 +478,13 @@ async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
|
454
478
|
*/
|
|
455
479
|
async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
456
480
|
value: Initial,
|
|
457
|
-
first: (value: Initial) => First,
|
|
458
|
-
second: (value:
|
|
459
|
-
third: (value:
|
|
460
|
-
fourth: (value:
|
|
461
|
-
fifth: (value:
|
|
462
|
-
sixth: (value:
|
|
463
|
-
): Promise<
|
|
481
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
482
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
483
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
484
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
485
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
486
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
487
|
+
): Promise<UnwrapValue<Sixth>>;
|
|
464
488
|
|
|
465
489
|
/**
|
|
466
490
|
* Pipe a value through a series of functions
|
|
@@ -469,14 +493,14 @@ async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
|
469
493
|
*/
|
|
470
494
|
async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
471
495
|
value: Initial,
|
|
472
|
-
first: (value: Initial) => First,
|
|
473
|
-
second: (value:
|
|
474
|
-
third: (value:
|
|
475
|
-
fourth: (value:
|
|
476
|
-
fifth: (value:
|
|
477
|
-
sixth: (value:
|
|
478
|
-
seventh: (value:
|
|
479
|
-
): Promise<
|
|
496
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
497
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
498
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
499
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
500
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
501
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
502
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
503
|
+
): Promise<UnwrapValue<Seventh>>;
|
|
480
504
|
|
|
481
505
|
/**
|
|
482
506
|
* Pipe a value through a series of functions
|
|
@@ -485,15 +509,15 @@ async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Se
|
|
|
485
509
|
*/
|
|
486
510
|
async function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
|
|
487
511
|
value: Initial,
|
|
488
|
-
first: (value: Initial) => First,
|
|
489
|
-
second: (value:
|
|
490
|
-
third: (value:
|
|
491
|
-
fourth: (value:
|
|
492
|
-
fifth: (value:
|
|
493
|
-
sixth: (value:
|
|
494
|
-
seventh: (value:
|
|
495
|
-
eighth: (value:
|
|
496
|
-
): Promise<
|
|
512
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
513
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
514
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
515
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
516
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
517
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
518
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
519
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
520
|
+
): Promise<UnwrapValue<Eighth>>;
|
|
497
521
|
|
|
498
522
|
/**
|
|
499
523
|
* Pipe a value through a series of functions
|
|
@@ -513,16 +537,16 @@ async function asyncPipe<
|
|
|
513
537
|
Ninth,
|
|
514
538
|
>(
|
|
515
539
|
value: Initial,
|
|
516
|
-
first: (value: Initial) => First,
|
|
517
|
-
second: (value:
|
|
518
|
-
third: (value:
|
|
519
|
-
fourth: (value:
|
|
520
|
-
fifth: (value:
|
|
521
|
-
sixth: (value:
|
|
522
|
-
seventh: (value:
|
|
523
|
-
eighth: (value:
|
|
524
|
-
ninth: (value:
|
|
525
|
-
): Promise<
|
|
540
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
541
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
542
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
543
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
544
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
545
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
546
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
547
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
548
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
549
|
+
): Promise<UnwrapValue<Ninth>>;
|
|
526
550
|
|
|
527
551
|
/**
|
|
528
552
|
* Pipe a value through a series of functions
|
|
@@ -543,17 +567,17 @@ async function asyncPipe<
|
|
|
543
567
|
Tenth,
|
|
544
568
|
>(
|
|
545
569
|
value: Initial,
|
|
546
|
-
first: (value: Initial) => First,
|
|
547
|
-
second: (value:
|
|
548
|
-
third: (value:
|
|
549
|
-
fourth: (value:
|
|
550
|
-
fifth: (value:
|
|
551
|
-
sixth: (value:
|
|
552
|
-
seventh: (value:
|
|
553
|
-
eighth: (value:
|
|
554
|
-
ninth: (value:
|
|
555
|
-
tenth: (value:
|
|
556
|
-
): Promise<
|
|
570
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
571
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
572
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
573
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
574
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
575
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
576
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
577
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
578
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
579
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
580
|
+
): Promise<UnwrapValue<Tenth>>;
|
|
557
581
|
|
|
558
582
|
/**
|
|
559
583
|
* Pipe a value through a series of functions
|
|
@@ -563,7 +587,7 @@ async function asyncPipe<
|
|
|
563
587
|
async function asyncPipe<Value>(
|
|
564
588
|
value: Value,
|
|
565
589
|
...pipes: Array<(value: Value) => Value>
|
|
566
|
-
): Promise<Value
|
|
590
|
+
): Promise<UnwrapValue<Value>>;
|
|
567
591
|
|
|
568
592
|
/**
|
|
569
593
|
* Pipe a value through a series of functions
|
|
@@ -593,7 +617,10 @@ async function asyncPipe(
|
|
|
593
617
|
* @param value Initial value
|
|
594
618
|
* @returns Piped result
|
|
595
619
|
*/
|
|
596
|
-
export function pipe<Initial,
|
|
620
|
+
export function pipe<Initial, Piped>(
|
|
621
|
+
value: Initial,
|
|
622
|
+
pipe: (value: UnwrapValue<Initial>) => Piped,
|
|
623
|
+
): UnwrapValue<Piped>;
|
|
597
624
|
|
|
598
625
|
/**
|
|
599
626
|
* Pipe a value through a series of functions
|
|
@@ -602,9 +629,9 @@ export function pipe<Initial, Pipe>(value: Initial, first: (value: Initial) => P
|
|
|
602
629
|
*/
|
|
603
630
|
export function pipe<Initial, First, Second>(
|
|
604
631
|
value: Initial,
|
|
605
|
-
first: (value: Initial) => First,
|
|
606
|
-
second: (value: First) => Second,
|
|
607
|
-
): Second
|
|
632
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
633
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
634
|
+
): UnwrapValue<Second>;
|
|
608
635
|
|
|
609
636
|
/**
|
|
610
637
|
* Pipe a value through a series of functions
|
|
@@ -613,10 +640,10 @@ export function pipe<Initial, First, Second>(
|
|
|
613
640
|
*/
|
|
614
641
|
export function pipe<Initial, First, Second, Third>(
|
|
615
642
|
value: Initial,
|
|
616
|
-
first: (value: Initial) => First,
|
|
617
|
-
second: (value: First) => Second,
|
|
618
|
-
third: (value: Second) => Third,
|
|
619
|
-
): Third
|
|
643
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
644
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
645
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
646
|
+
): UnwrapValue<Third>;
|
|
620
647
|
|
|
621
648
|
/**
|
|
622
649
|
* Pipe a value through a series of functions
|
|
@@ -625,11 +652,11 @@ export function pipe<Initial, First, Second, Third>(
|
|
|
625
652
|
*/
|
|
626
653
|
export function pipe<Initial, First, Second, Third, Fourth>(
|
|
627
654
|
value: Initial,
|
|
628
|
-
first: (value: Initial) => First,
|
|
629
|
-
second: (value: First) => Second,
|
|
630
|
-
third: (value: Second) => Third,
|
|
631
|
-
fourth: (value: Third) => Fourth,
|
|
632
|
-
): Fourth
|
|
655
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
656
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
657
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
658
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
659
|
+
): UnwrapValue<Fourth>;
|
|
633
660
|
|
|
634
661
|
/**
|
|
635
662
|
* Pipe a value through a series of functions
|
|
@@ -638,12 +665,12 @@ export function pipe<Initial, First, Second, Third, Fourth>(
|
|
|
638
665
|
*/
|
|
639
666
|
export function pipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
640
667
|
value: Initial,
|
|
641
|
-
first: (value: Initial) => First,
|
|
642
|
-
second: (value: First) => Second,
|
|
643
|
-
third: (value: Second) => Third,
|
|
644
|
-
fourth: (value: Third) => Fourth,
|
|
645
|
-
fifth: (value: Fourth) => Fifth,
|
|
646
|
-
): Fifth
|
|
668
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
669
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
670
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
671
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
672
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
673
|
+
): UnwrapValue<Fifth>;
|
|
647
674
|
|
|
648
675
|
/**
|
|
649
676
|
* Pipe a value through a series of functions
|
|
@@ -652,13 +679,13 @@ export function pipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
|
652
679
|
*/
|
|
653
680
|
export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
654
681
|
value: Initial,
|
|
655
|
-
first: (value: Initial) => First,
|
|
656
|
-
second: (value: First) => Second,
|
|
657
|
-
third: (value: Second) => Third,
|
|
658
|
-
fourth: (value: Third) => Fourth,
|
|
659
|
-
fifth: (value: Fourth) => Fifth,
|
|
660
|
-
sixth: (value: Fifth) => Sixth,
|
|
661
|
-
): Sixth
|
|
682
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
683
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
684
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
685
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
686
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
687
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
688
|
+
): UnwrapValue<Sixth>;
|
|
662
689
|
|
|
663
690
|
/**
|
|
664
691
|
* Pipe a value through a series of functions
|
|
@@ -667,14 +694,14 @@ export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
|
667
694
|
*/
|
|
668
695
|
export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
669
696
|
value: Initial,
|
|
670
|
-
first: (value: Initial) => First,
|
|
671
|
-
second: (value: First) => Second,
|
|
672
|
-
third: (value: Second) => Third,
|
|
673
|
-
fourth: (value: Third) => Fourth,
|
|
674
|
-
fifth: (value: Fourth) => Fifth,
|
|
675
|
-
sixth: (value: Fifth) => Sixth,
|
|
676
|
-
seventh: (value: Sixth) => Seventh,
|
|
677
|
-
): Seventh
|
|
697
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
698
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
699
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
700
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
701
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
702
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
703
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
704
|
+
): UnwrapValue<Seventh>;
|
|
678
705
|
|
|
679
706
|
/**
|
|
680
707
|
* Pipe a value through a series of functions
|
|
@@ -683,15 +710,15 @@ export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Sevent
|
|
|
683
710
|
*/
|
|
684
711
|
export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
|
|
685
712
|
value: Initial,
|
|
686
|
-
first: (value: Initial) => First,
|
|
687
|
-
second: (value: First) => Second,
|
|
688
|
-
third: (value: Second) => Third,
|
|
689
|
-
fourth: (value: Third) => Fourth,
|
|
690
|
-
fifth: (value: Fourth) => Fifth,
|
|
691
|
-
sixth: (value: Fifth) => Sixth,
|
|
692
|
-
seventh: (value: Sixth) => Seventh,
|
|
693
|
-
eighth: (value: Seventh) => Eighth,
|
|
694
|
-
): Eighth
|
|
713
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
714
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
715
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
716
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
717
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
718
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
719
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
720
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
721
|
+
): UnwrapValue<Eighth>;
|
|
695
722
|
|
|
696
723
|
/**
|
|
697
724
|
* Pipe a value through a series of functions
|
|
@@ -700,16 +727,16 @@ export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Sevent
|
|
|
700
727
|
*/
|
|
701
728
|
export function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(
|
|
702
729
|
value: Initial,
|
|
703
|
-
first: (value: Initial) => First,
|
|
704
|
-
second: (value: First) => Second,
|
|
705
|
-
third: (value: Second) => Third,
|
|
706
|
-
fourth: (value: Third) => Fourth,
|
|
707
|
-
fifth: (value: Fourth) => Fifth,
|
|
708
|
-
sixth: (value: Fifth) => Sixth,
|
|
709
|
-
seventh: (value: Sixth) => Seventh,
|
|
710
|
-
eighth: (value: Seventh) => Eighth,
|
|
711
|
-
ninth: (value: Eighth) => Ninth,
|
|
712
|
-
): Ninth
|
|
730
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
731
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
732
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
733
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
734
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
735
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
736
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
737
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
738
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
739
|
+
): UnwrapValue<Ninth>;
|
|
713
740
|
|
|
714
741
|
/**
|
|
715
742
|
* Pipe a value through a series of functions
|
|
@@ -730,24 +757,27 @@ export function pipe<
|
|
|
730
757
|
Tenth,
|
|
731
758
|
>(
|
|
732
759
|
value: Initial,
|
|
733
|
-
first: (value: Initial) => First,
|
|
734
|
-
second: (value: First) => Second,
|
|
735
|
-
third: (value: Second) => Third,
|
|
736
|
-
fourth: (value: Third) => Fourth,
|
|
737
|
-
fifth: (value: Fourth) => Fifth,
|
|
738
|
-
sixth: (value: Fifth) => Sixth,
|
|
739
|
-
seventh: (value: Sixth) => Seventh,
|
|
740
|
-
eighth: (value: Seventh) => Eighth,
|
|
741
|
-
ninth: (value: Eighth) => Ninth,
|
|
742
|
-
tenth: (value: Ninth) => Tenth,
|
|
743
|
-
): Tenth
|
|
760
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
761
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
762
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
763
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
764
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
765
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
766
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
767
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
768
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
769
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
770
|
+
): UnwrapValue<Tenth>;
|
|
744
771
|
|
|
745
772
|
/**
|
|
746
773
|
* Pipe a value through a series of functions
|
|
747
774
|
* @param value Initial value
|
|
748
775
|
* @returns Piped result
|
|
749
776
|
*/
|
|
750
|
-
export function pipe<Value>(
|
|
777
|
+
export function pipe<Value>(
|
|
778
|
+
value: Value,
|
|
779
|
+
...pipes: Array<(value: Value) => Value>
|
|
780
|
+
): UnwrapValue<Value>;
|
|
751
781
|
|
|
752
782
|
/**
|
|
753
783
|
* Pipe a value through a series of functions
|
|
@@ -756,7 +786,7 @@ export function pipe<Value>(value: Value, ...pipes: Array<(value: Value) => Valu
|
|
|
756
786
|
*/
|
|
757
787
|
export function pipe(value: unknown, ...pipes: Array<(value: unknown) => unknown>): unknown;
|
|
758
788
|
|
|
759
|
-
export function pipe(value: unknown, ...pipes:
|
|
789
|
+
export function pipe(value: unknown, ...pipes: GenericCallback[]): unknown {
|
|
760
790
|
assertPipeFunctions(pipes);
|
|
761
791
|
|
|
762
792
|
return work(value, pipes, false);
|
|
@@ -770,37 +800,63 @@ pipe.async = asyncPipe;
|
|
|
770
800
|
|
|
771
801
|
// #region Work
|
|
772
802
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
803
|
+
async function asyncWork(
|
|
804
|
+
initial: unknown,
|
|
805
|
+
functions: GenericCallback[],
|
|
806
|
+
flow: boolean,
|
|
807
|
+
): Promise<unknown> {
|
|
776
808
|
const {length} = functions;
|
|
777
809
|
|
|
778
|
-
let transformed = initial;
|
|
810
|
+
let transformed = unwrapValue(initial);
|
|
779
811
|
|
|
780
812
|
for (let index = 0; index < length; index += 1) {
|
|
781
813
|
const fn = functions[index];
|
|
782
814
|
|
|
783
|
-
|
|
815
|
+
const value =
|
|
784
816
|
flow && index === 0 && Array.isArray(initial)
|
|
785
817
|
? await fn(...(initial as unknown[]))
|
|
786
818
|
: await fn(transformed);
|
|
819
|
+
|
|
820
|
+
transformed = unwrapValue(value);
|
|
787
821
|
}
|
|
788
822
|
|
|
789
823
|
return transformed;
|
|
790
824
|
}
|
|
791
825
|
|
|
792
|
-
function
|
|
826
|
+
function unwrapValue(value: unknown, flow?: boolean, nested?: boolean): unknown {
|
|
827
|
+
if (typeof value === 'function') {
|
|
828
|
+
if (nested != null) {
|
|
829
|
+
throw new TypeError(MESSAGE_NESTING);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
return unwrapValue(value(), flow, true);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (flow != null && value instanceof Promise) {
|
|
836
|
+
throw new TypeError(flow ? MESSAGE_FLOW_PROMISE : MESSAGE_PIPE_PROMISE);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
if (isError(value)) {
|
|
840
|
+
throw value.error;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
return isOk(value) ? value.value : value;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function work(initial: unknown, functions: GenericCallback[], flow: boolean): unknown {
|
|
793
847
|
const {length} = functions;
|
|
794
848
|
|
|
795
|
-
let transformed = initial;
|
|
849
|
+
let transformed = unwrapValue(initial, flow);
|
|
796
850
|
|
|
797
851
|
for (let index = 0; index < length; index += 1) {
|
|
798
852
|
const fn = functions[index];
|
|
799
853
|
|
|
800
|
-
|
|
854
|
+
const value =
|
|
801
855
|
flow && index === 0 && Array.isArray(initial)
|
|
802
856
|
? fn(...(initial as unknown[]))
|
|
803
857
|
: fn(transformed);
|
|
858
|
+
|
|
859
|
+
transformed = unwrapValue(value, flow);
|
|
804
860
|
}
|
|
805
861
|
|
|
806
862
|
return transformed;
|
|
@@ -810,21 +866,27 @@ function work(initial: unknown, functions: Function[], flow: boolean): unknown {
|
|
|
810
866
|
|
|
811
867
|
// #endregion
|
|
812
868
|
|
|
813
|
-
// #
|
|
869
|
+
// #region Variables
|
|
870
|
+
|
|
871
|
+
const MESSAGE_FLOW_ARRAY = 'Flow expected to receive an array of functions';
|
|
872
|
+
|
|
873
|
+
const MESSAGE_FLOW_PROMISE = 'Synchronous Flow received a promise. Use `flow.async` instead.';
|
|
874
|
+
|
|
875
|
+
const MESSAGE_NESTING = 'Return values are too deeply nested.';
|
|
814
876
|
|
|
815
|
-
const
|
|
877
|
+
const MESSAGE_PIPE_ARRAY = 'Pipe expected to receive an array of functions';
|
|
816
878
|
|
|
817
|
-
const
|
|
879
|
+
const MESSAGE_PIPE_PROMISE = 'Synchronous Pipe received a promise. Use `pipe.async` instead.';
|
|
818
880
|
|
|
819
881
|
const assertFlowFunctions: Asserter<Function[]> = assert.condition(
|
|
820
882
|
value => Array.isArray(value) && value.every(item => typeof item === 'function'),
|
|
821
|
-
|
|
883
|
+
MESSAGE_FLOW_ARRAY,
|
|
822
884
|
TypeError,
|
|
823
885
|
);
|
|
824
886
|
|
|
825
887
|
const assertPipeFunctions: Asserter<Function[]> = assert.condition(
|
|
826
888
|
value => Array.isArray(value) && value.every(item => typeof item === 'function'),
|
|
827
|
-
|
|
889
|
+
MESSAGE_PIPE_ARRAY,
|
|
828
890
|
TypeError,
|
|
829
891
|
);
|
|
830
892
|
|