@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
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
import {pipe} from '../../function/work';
|
|
2
|
+
import {isError, isOk} from '../../internal/result';
|
|
3
|
+
import type {GenericCallback} from '../../models';
|
|
4
|
+
import {attempt} from '../index';
|
|
5
|
+
import type {Result, UnwrapValue} from '../models';
|
|
6
|
+
|
|
7
|
+
// #region Types
|
|
8
|
+
|
|
9
|
+
type WrapValue<Value> = Result<UnwrapValue<Value>>;
|
|
10
|
+
|
|
11
|
+
// #endregion
|
|
12
|
+
|
|
13
|
+
// #region Functions
|
|
14
|
+
|
|
15
|
+
// #region Asynchronous
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Attempt to pipe a result through a function
|
|
19
|
+
* @param initial Initial result
|
|
20
|
+
* @returns Piped result
|
|
21
|
+
*/
|
|
22
|
+
function attemptAsyncPipe<Initial, Piped>(
|
|
23
|
+
initial: Result<Initial>,
|
|
24
|
+
pipe: (value: UnwrapValue<Initial>) => Piped,
|
|
25
|
+
): Promise<WrapValue<Piped>>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Attempt to pipe a result through a series of functions
|
|
29
|
+
* @param initial Initial result
|
|
30
|
+
* @returns Piped result
|
|
31
|
+
*/
|
|
32
|
+
function attemptAsyncPipe<Initial, First, Second>(
|
|
33
|
+
initial: Result<Initial>,
|
|
34
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
35
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
36
|
+
): Promise<WrapValue<Second>>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Attempt to pipe a result through a series of functions
|
|
40
|
+
* @param initial Initial result
|
|
41
|
+
* @returns Piped result
|
|
42
|
+
*/
|
|
43
|
+
function attemptAsyncPipe<Initial, First, Second, Third>(
|
|
44
|
+
initial: Result<Initial>,
|
|
45
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
46
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
47
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
48
|
+
): Promise<WrapValue<Third>>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Attempt to pipe a result through a series of functions
|
|
52
|
+
* @param initial Initial result
|
|
53
|
+
* @returns Piped result
|
|
54
|
+
*/
|
|
55
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth>(
|
|
56
|
+
initial: Result<Initial>,
|
|
57
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
58
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
59
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
60
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
61
|
+
): Promise<WrapValue<Fourth>>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Attempt to pipe a result through a series of functions
|
|
65
|
+
* @param initial Initial result
|
|
66
|
+
* @returns Piped result
|
|
67
|
+
*/
|
|
68
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
69
|
+
initial: Result<Initial>,
|
|
70
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
71
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
72
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
73
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
74
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
75
|
+
): Promise<WrapValue<Fifth>>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Attempt to pipe a result through a series of functions
|
|
79
|
+
* @param initial Initial result
|
|
80
|
+
* @returns Piped result
|
|
81
|
+
*/
|
|
82
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
83
|
+
initial: Result<Initial>,
|
|
84
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
85
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
86
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
87
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
88
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
89
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
90
|
+
): Promise<WrapValue<Sixth>>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Attempt to pipe a result through a series of functions
|
|
94
|
+
* @param initial Initial result
|
|
95
|
+
* @returns Piped result
|
|
96
|
+
*/
|
|
97
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
98
|
+
initial: Result<Initial>,
|
|
99
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
100
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
101
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
102
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
103
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
104
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
105
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
106
|
+
): Promise<WrapValue<Seventh>>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Attempt to pipe a result through a series of functions
|
|
110
|
+
* @param initial Initial result
|
|
111
|
+
* @returns Piped result
|
|
112
|
+
*/
|
|
113
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
|
|
114
|
+
initial: Result<Initial>,
|
|
115
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
116
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
117
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
118
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
119
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
120
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
121
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
122
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
123
|
+
): Promise<WrapValue<Eighth>>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Attempt to pipe a result through a series of functions
|
|
127
|
+
* @param initial Initial result
|
|
128
|
+
* @returns Piped result
|
|
129
|
+
*/
|
|
130
|
+
function attemptAsyncPipe<
|
|
131
|
+
Initial,
|
|
132
|
+
First,
|
|
133
|
+
Second,
|
|
134
|
+
Third,
|
|
135
|
+
Fourth,
|
|
136
|
+
Fifth,
|
|
137
|
+
Sixth,
|
|
138
|
+
Seventh,
|
|
139
|
+
Eighth,
|
|
140
|
+
Ninth,
|
|
141
|
+
>(
|
|
142
|
+
initial: Result<Initial>,
|
|
143
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
144
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
145
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
146
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
147
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
148
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
149
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
150
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
151
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
152
|
+
): Promise<WrapValue<Ninth>>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Attempt to pipe a result through a series of functions
|
|
156
|
+
* @param initial Initial result
|
|
157
|
+
* @returns Piped result
|
|
158
|
+
*/
|
|
159
|
+
function attemptAsyncPipe<
|
|
160
|
+
Initial,
|
|
161
|
+
First,
|
|
162
|
+
Second,
|
|
163
|
+
Third,
|
|
164
|
+
Fourth,
|
|
165
|
+
Fifth,
|
|
166
|
+
Sixth,
|
|
167
|
+
Seventh,
|
|
168
|
+
Eighth,
|
|
169
|
+
Ninth,
|
|
170
|
+
Tenth,
|
|
171
|
+
>(
|
|
172
|
+
initial: Result<Initial>,
|
|
173
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
174
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
175
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
176
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
177
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
178
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
179
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
180
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
181
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
182
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
183
|
+
): Promise<WrapValue<Tenth>>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Attempt to pipe a value through a function
|
|
187
|
+
* @param initial Initial value
|
|
188
|
+
* @returns Piped result
|
|
189
|
+
*/
|
|
190
|
+
function attemptAsyncPipe<Initial, Piped>(
|
|
191
|
+
initial: GenericCallback | Initial,
|
|
192
|
+
pipe: (value: UnwrapValue<Initial>) => Piped,
|
|
193
|
+
): Promise<WrapValue<Piped>>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Attempt to pipe a value through a series of functions
|
|
197
|
+
* @param initial Initial value
|
|
198
|
+
* @returns Piped result
|
|
199
|
+
*/
|
|
200
|
+
function attemptAsyncPipe<Initial, First, Second>(
|
|
201
|
+
initial: GenericCallback | Initial,
|
|
202
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
203
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
204
|
+
): Promise<WrapValue<Second>>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Attempt to pipe a value through a series of functions
|
|
208
|
+
* @param initial Initial value
|
|
209
|
+
* @returns Piped result
|
|
210
|
+
*/
|
|
211
|
+
function attemptAsyncPipe<Initial, First, Second, Third>(
|
|
212
|
+
initial: GenericCallback | Initial,
|
|
213
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
214
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
215
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
216
|
+
): Promise<WrapValue<Third>>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Attempt to pipe a value through a series of functions
|
|
220
|
+
* @param initial Initial value
|
|
221
|
+
* @returns Piped result
|
|
222
|
+
*/
|
|
223
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth>(
|
|
224
|
+
initial: GenericCallback | Initial,
|
|
225
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
226
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
227
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
228
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
229
|
+
): Promise<WrapValue<Fourth>>;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Attempt to pipe a value through a series of functions
|
|
233
|
+
* @param initial Initial value
|
|
234
|
+
* @returns Piped result
|
|
235
|
+
*/
|
|
236
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
237
|
+
initial: GenericCallback | Initial,
|
|
238
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
239
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
240
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
241
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
242
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
243
|
+
): Promise<WrapValue<Fifth>>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Attempt to pipe a value through a series of functions
|
|
247
|
+
* @param initial Initial value
|
|
248
|
+
* @returns Piped result
|
|
249
|
+
*/
|
|
250
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
251
|
+
initial: GenericCallback | Initial,
|
|
252
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
253
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
254
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
255
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
256
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
257
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
258
|
+
): Promise<WrapValue<Sixth>>;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Attempt to pipe a value through a series of functions
|
|
262
|
+
* @param initial Initial value
|
|
263
|
+
* @returns Piped result
|
|
264
|
+
*/
|
|
265
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
266
|
+
initial: GenericCallback | Initial,
|
|
267
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
268
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
269
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
270
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
271
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
272
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
273
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
274
|
+
): Promise<WrapValue<Seventh>>;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Attempt to pipe a value through a series of functions
|
|
278
|
+
* @param initial Initial value
|
|
279
|
+
* @returns Piped result
|
|
280
|
+
*/
|
|
281
|
+
function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
|
|
282
|
+
initial: GenericCallback | Initial,
|
|
283
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
284
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
285
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
286
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
287
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
288
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
289
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
290
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
291
|
+
): Promise<WrapValue<Eighth>>;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Attempt to pipe a value through a series of functions
|
|
295
|
+
* @param initial Initial value
|
|
296
|
+
* @returns Piped result
|
|
297
|
+
*/
|
|
298
|
+
function attemptAsyncPipe<
|
|
299
|
+
Initial,
|
|
300
|
+
First,
|
|
301
|
+
Second,
|
|
302
|
+
Third,
|
|
303
|
+
Fourth,
|
|
304
|
+
Fifth,
|
|
305
|
+
Sixth,
|
|
306
|
+
Seventh,
|
|
307
|
+
Eighth,
|
|
308
|
+
Ninth,
|
|
309
|
+
>(
|
|
310
|
+
initial: GenericCallback | Initial,
|
|
311
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
312
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
313
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
314
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
315
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
316
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
317
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
318
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
319
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
320
|
+
): Promise<WrapValue<Ninth>>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Attempt to pipe a value through a series of functions
|
|
324
|
+
* @param initial Initial value
|
|
325
|
+
* @returns Piped result
|
|
326
|
+
*/
|
|
327
|
+
function attemptAsyncPipe<
|
|
328
|
+
Initial,
|
|
329
|
+
First,
|
|
330
|
+
Second,
|
|
331
|
+
Third,
|
|
332
|
+
Fourth,
|
|
333
|
+
Fifth,
|
|
334
|
+
Sixth,
|
|
335
|
+
Seventh,
|
|
336
|
+
Eighth,
|
|
337
|
+
Ninth,
|
|
338
|
+
Tenth,
|
|
339
|
+
>(
|
|
340
|
+
initial: GenericCallback | Initial,
|
|
341
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
342
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
343
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
344
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
345
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
346
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
347
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
348
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
349
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
350
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
351
|
+
): Promise<WrapValue<Tenth>>;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Attempt to pipe a result through a series of functions
|
|
355
|
+
* @param initial Initial result
|
|
356
|
+
* @returns Piped result
|
|
357
|
+
*/
|
|
358
|
+
function attemptAsyncPipe<Initial>(
|
|
359
|
+
initial: Result<Initial>,
|
|
360
|
+
first?: (value: UnwrapValue<Initial>) => unknown,
|
|
361
|
+
...seconds: Array<(value: unknown) => unknown>
|
|
362
|
+
): Promise<WrapValue<Initial>>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Attempt to pipe an item through a series of functions
|
|
366
|
+
* @param item Initial value
|
|
367
|
+
* @returns Piped result
|
|
368
|
+
*/
|
|
369
|
+
function attemptAsyncPipe<Initial>(
|
|
370
|
+
initial: GenericCallback | Initial,
|
|
371
|
+
first?: (value: UnwrapValue<Initial>) => unknown,
|
|
372
|
+
...seconds: Array<(value: unknown) => unknown>
|
|
373
|
+
): Promise<WrapValue<Initial>>;
|
|
374
|
+
|
|
375
|
+
async function attemptAsyncPipe(
|
|
376
|
+
initial: unknown,
|
|
377
|
+
first?: (value: unknown) => unknown,
|
|
378
|
+
...seconds: Array<(value: unknown) => unknown>
|
|
379
|
+
): Promise<Result<unknown>> {
|
|
380
|
+
return attempt.async(() => {
|
|
381
|
+
if (isError(initial)) {
|
|
382
|
+
throw initial.error;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const value =
|
|
386
|
+
typeof initial === 'function'
|
|
387
|
+
? (initial as Function)()
|
|
388
|
+
: isOk(initial)
|
|
389
|
+
? initial.value
|
|
390
|
+
: initial;
|
|
391
|
+
|
|
392
|
+
if (first == null) {
|
|
393
|
+
return value;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return pipe.async(value, ...([first, ...seconds] as GenericCallback[]));
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// #endregion
|
|
401
|
+
|
|
402
|
+
// #region Synchronous
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Attempt to pipe a result through a function
|
|
406
|
+
* @param initial Initial result
|
|
407
|
+
* @returns Piped result
|
|
408
|
+
*/
|
|
409
|
+
export function attemptPipe<Initial, Piped>(
|
|
410
|
+
initial: Result<Initial>,
|
|
411
|
+
pipe: (value: UnwrapValue<Initial>) => Piped,
|
|
412
|
+
): WrapValue<Piped>;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Attempt to pipe a result through a series of functions
|
|
416
|
+
* @param initial Initial result
|
|
417
|
+
* @returns Piped result
|
|
418
|
+
*/
|
|
419
|
+
export function attemptPipe<Initial, First, Second>(
|
|
420
|
+
initial: Result<Initial>,
|
|
421
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
422
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
423
|
+
): WrapValue<Second>;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Attempt to pipe a result through a series of functions
|
|
427
|
+
* @param initial Initial result
|
|
428
|
+
* @returns Piped result
|
|
429
|
+
*/
|
|
430
|
+
export function attemptPipe<Initial, First, Second, Third>(
|
|
431
|
+
initial: Result<Initial>,
|
|
432
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
433
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
434
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
435
|
+
): WrapValue<Third>;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Attempt to pipe a result through a series of functions
|
|
439
|
+
* @param initial Initial result
|
|
440
|
+
* @returns Piped result
|
|
441
|
+
*/
|
|
442
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth>(
|
|
443
|
+
initial: Result<Initial>,
|
|
444
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
445
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
446
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
447
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
448
|
+
): WrapValue<Fourth>;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Attempt to pipe a result through a series of functions
|
|
452
|
+
* @param initial Initial result
|
|
453
|
+
* @returns Piped result
|
|
454
|
+
*/
|
|
455
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
456
|
+
initial: Result<Initial>,
|
|
457
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
458
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
459
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
460
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
461
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
462
|
+
): WrapValue<Fifth>;
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Attempt to pipe a result through a series of functions
|
|
466
|
+
* @param initial Initial result
|
|
467
|
+
* @returns Piped result
|
|
468
|
+
*/
|
|
469
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
470
|
+
initial: Result<Initial>,
|
|
471
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
472
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
473
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
474
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
475
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
476
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
477
|
+
): WrapValue<Sixth>;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Attempt to pipe a result through a series of functions
|
|
481
|
+
* @param initial Initial result
|
|
482
|
+
* @returns Piped result
|
|
483
|
+
*/
|
|
484
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
485
|
+
initial: Result<Initial>,
|
|
486
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
487
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
488
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
489
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
490
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
491
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
492
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
493
|
+
): WrapValue<Seventh>;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Attempt to pipe a result through a series of functions
|
|
497
|
+
* @param initial Initial result
|
|
498
|
+
* @returns Piped result
|
|
499
|
+
*/
|
|
500
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
|
|
501
|
+
initial: Result<Initial>,
|
|
502
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
503
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
504
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
505
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
506
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
507
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
508
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
509
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
510
|
+
): WrapValue<Eighth>;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Attempt to pipe a result through a series of functions
|
|
514
|
+
* @param initial Initial result
|
|
515
|
+
* @returns Piped result
|
|
516
|
+
*/
|
|
517
|
+
export function attemptPipe<
|
|
518
|
+
Initial,
|
|
519
|
+
First,
|
|
520
|
+
Second,
|
|
521
|
+
Third,
|
|
522
|
+
Fourth,
|
|
523
|
+
Fifth,
|
|
524
|
+
Sixth,
|
|
525
|
+
Seventh,
|
|
526
|
+
Eighth,
|
|
527
|
+
Ninth,
|
|
528
|
+
>(
|
|
529
|
+
initial: Result<Initial>,
|
|
530
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
531
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
532
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
533
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
534
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
535
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
536
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
537
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
538
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
539
|
+
): WrapValue<Ninth>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Attempt to pipe a result through a series of functions
|
|
543
|
+
* @param initial Initial result
|
|
544
|
+
* @returns Piped result
|
|
545
|
+
*/
|
|
546
|
+
export function attemptPipe<
|
|
547
|
+
Initial,
|
|
548
|
+
First,
|
|
549
|
+
Second,
|
|
550
|
+
Third,
|
|
551
|
+
Fourth,
|
|
552
|
+
Fifth,
|
|
553
|
+
Sixth,
|
|
554
|
+
Seventh,
|
|
555
|
+
Eighth,
|
|
556
|
+
Ninth,
|
|
557
|
+
Tenth,
|
|
558
|
+
>(
|
|
559
|
+
initial: Result<Initial>,
|
|
560
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
561
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
562
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
563
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
564
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
565
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
566
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
567
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
568
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
569
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
570
|
+
): WrapValue<Tenth>;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Attempt to pipe a value through a function
|
|
574
|
+
* @param initial Initial value
|
|
575
|
+
* @returns Piped result
|
|
576
|
+
*/
|
|
577
|
+
export function attemptPipe<Initial, Pipe>(
|
|
578
|
+
initial: GenericCallback | Initial,
|
|
579
|
+
pipe: (value: UnwrapValue<Initial>) => Pipe,
|
|
580
|
+
): WrapValue<Pipe>;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Attempt to pipe a value through a series of functions
|
|
584
|
+
* @param initial Initial value
|
|
585
|
+
* @returns Piped result
|
|
586
|
+
*/
|
|
587
|
+
export function attemptPipe<Initial, First, Second>(
|
|
588
|
+
initial: GenericCallback | Initial,
|
|
589
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
590
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
591
|
+
): WrapValue<Second>;
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Attempt to pipe a value through a series of functions
|
|
595
|
+
* @param initial Initial value
|
|
596
|
+
* @returns Piped result
|
|
597
|
+
*/
|
|
598
|
+
export function attemptPipe<Initial, First, Second, Third>(
|
|
599
|
+
initial: GenericCallback | Initial,
|
|
600
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
601
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
602
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
603
|
+
): WrapValue<Third>;
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Attempt to pipe a value through a series of functions
|
|
607
|
+
* @param initial Initial value
|
|
608
|
+
* @returns Piped result
|
|
609
|
+
*/
|
|
610
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth>(
|
|
611
|
+
initial: GenericCallback | Initial,
|
|
612
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
613
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
614
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
615
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
616
|
+
): WrapValue<Fourth>;
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Attempt to pipe a value through a series of functions
|
|
620
|
+
* @param initial Initial value
|
|
621
|
+
* @returns Piped result
|
|
622
|
+
*/
|
|
623
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth>(
|
|
624
|
+
initial: GenericCallback | Initial,
|
|
625
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
626
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
627
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
628
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
629
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
630
|
+
): WrapValue<Fifth>;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Attempt to pipe a value through a series of functions
|
|
634
|
+
* @param initial Initial value
|
|
635
|
+
* @returns Piped result
|
|
636
|
+
*/
|
|
637
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(
|
|
638
|
+
initial: GenericCallback | Initial,
|
|
639
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
640
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
641
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
642
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
643
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
644
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
645
|
+
): WrapValue<Sixth>;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Attempt to pipe a value through a series of functions
|
|
649
|
+
* @param initial Initial value
|
|
650
|
+
* @returns Piped result
|
|
651
|
+
*/
|
|
652
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(
|
|
653
|
+
initial: GenericCallback | Initial,
|
|
654
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
655
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
656
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
657
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
658
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
659
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
660
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
661
|
+
): WrapValue<Seventh>;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Attempt to pipe a value through a series of functions
|
|
665
|
+
* @param initial Initial value
|
|
666
|
+
* @returns Piped result
|
|
667
|
+
*/
|
|
668
|
+
export function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(
|
|
669
|
+
initial: GenericCallback | Initial,
|
|
670
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
671
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
672
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
673
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
674
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
675
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
676
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
677
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
678
|
+
): WrapValue<Eighth>;
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Attempt to pipe a value through a series of functions
|
|
682
|
+
* @param initial Initial value
|
|
683
|
+
* @returns Piped result
|
|
684
|
+
*/
|
|
685
|
+
export function attemptPipe<
|
|
686
|
+
Initial,
|
|
687
|
+
First,
|
|
688
|
+
Second,
|
|
689
|
+
Third,
|
|
690
|
+
Fourth,
|
|
691
|
+
Fifth,
|
|
692
|
+
Sixth,
|
|
693
|
+
Seventh,
|
|
694
|
+
Eighth,
|
|
695
|
+
Ninth,
|
|
696
|
+
>(
|
|
697
|
+
initial: GenericCallback | Initial,
|
|
698
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
699
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
700
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
701
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
702
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
703
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
704
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
705
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
706
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
707
|
+
): WrapValue<Ninth>;
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Attempt to pipe a value through a series of functions
|
|
711
|
+
* @param initial Initial value
|
|
712
|
+
* @returns Piped result
|
|
713
|
+
*/
|
|
714
|
+
export function attemptPipe<
|
|
715
|
+
Initial,
|
|
716
|
+
First,
|
|
717
|
+
Second,
|
|
718
|
+
Third,
|
|
719
|
+
Fourth,
|
|
720
|
+
Fifth,
|
|
721
|
+
Sixth,
|
|
722
|
+
Seventh,
|
|
723
|
+
Eighth,
|
|
724
|
+
Ninth,
|
|
725
|
+
Tenth,
|
|
726
|
+
>(
|
|
727
|
+
initial: GenericCallback | Initial,
|
|
728
|
+
first: (value: UnwrapValue<Initial>) => First,
|
|
729
|
+
second: (value: UnwrapValue<First>) => Second,
|
|
730
|
+
third: (value: UnwrapValue<Second>) => Third,
|
|
731
|
+
fourth: (value: UnwrapValue<Third>) => Fourth,
|
|
732
|
+
fifth: (value: UnwrapValue<Fourth>) => Fifth,
|
|
733
|
+
sixth: (value: UnwrapValue<Fifth>) => Sixth,
|
|
734
|
+
seventh: (value: UnwrapValue<Sixth>) => Seventh,
|
|
735
|
+
eighth: (value: UnwrapValue<Seventh>) => Eighth,
|
|
736
|
+
ninth: (value: UnwrapValue<Eighth>) => Ninth,
|
|
737
|
+
tenth: (value: UnwrapValue<Ninth>) => Tenth,
|
|
738
|
+
): WrapValue<Tenth>;
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Attempt to pipe a result through a series of functions
|
|
742
|
+
* @param initial Initial result
|
|
743
|
+
* @returns Piped result
|
|
744
|
+
*/
|
|
745
|
+
export function attemptPipe<Initial>(
|
|
746
|
+
initial: Result<Initial>,
|
|
747
|
+
first?: (value: UnwrapValue<Initial>) => unknown,
|
|
748
|
+
...seconds: Array<(value: unknown) => unknown>
|
|
749
|
+
): WrapValue<Initial>;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Attempt to pipe an item through a series of functions
|
|
753
|
+
* @param item Initial value
|
|
754
|
+
* @returns Piped result
|
|
755
|
+
*/
|
|
756
|
+
export function attemptPipe<Initial>(
|
|
757
|
+
initial: GenericCallback | Initial,
|
|
758
|
+
first?: (value: UnwrapValue<Initial>) => unknown,
|
|
759
|
+
...seconds: Array<(value: unknown) => unknown>
|
|
760
|
+
): WrapValue<Initial>;
|
|
761
|
+
|
|
762
|
+
export function attemptPipe(
|
|
763
|
+
initial: unknown,
|
|
764
|
+
first?: (value: unknown) => unknown,
|
|
765
|
+
...seconds: Array<(value: unknown) => unknown>
|
|
766
|
+
): WrapValue<unknown> {
|
|
767
|
+
return attempt(() => {
|
|
768
|
+
if (isError(initial)) {
|
|
769
|
+
throw initial.error;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const value =
|
|
773
|
+
typeof initial === 'function'
|
|
774
|
+
? (initial as Function)()
|
|
775
|
+
: isOk(initial)
|
|
776
|
+
? initial.value
|
|
777
|
+
: initial;
|
|
778
|
+
|
|
779
|
+
if (first == null) {
|
|
780
|
+
return value;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
return pipe(value, ...([first, ...seconds] as GenericCallback[]));
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
attemptPipe.async = attemptAsyncPipe;
|
|
788
|
+
|
|
789
|
+
// #endregion
|
|
790
|
+
|
|
791
|
+
// #endregion
|