t-tasks 1.0.1 → 1.0.2
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/either.d.ts +75 -44
- package/dist/maybe.d.ts +33 -2
- package/dist/t-tasks.esm.js +1 -1
- package/dist/t-tasks.esm.js.map +1 -1
- package/dist/t-tasks.js +1 -1
- package/dist/t-tasks.js.map +1 -1
- package/dist/t-tasks.modern.js +1 -1
- package/dist/t-tasks.modern.js.map +1 -1
- package/dist/t-tasks.umd.js +1 -1
- package/dist/t-tasks.umd.js.map +1 -1
- package/dist/task.d.ts +8 -0
- package/package.json +1 -1
- package/src/either.ts +107 -47
- package/src/maybe.ts +62 -2
- package/src/task.ts +20 -7
package/dist/either.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface Right<R, L> {
|
|
|
40
40
|
*/
|
|
41
41
|
matchTap(op: {
|
|
42
42
|
right: (value: R) => void;
|
|
43
|
-
left: (error:
|
|
43
|
+
left: (error: L) => void;
|
|
44
44
|
}): this;
|
|
45
45
|
/**
|
|
46
46
|
* Either transformer function
|
|
@@ -79,11 +79,11 @@ export interface Right<R, L> {
|
|
|
79
79
|
*/
|
|
80
80
|
matchMap<R2, R3 = R2>(this: Right<R, L>, op: {
|
|
81
81
|
right: (value: R) => R2;
|
|
82
|
-
left: (error:
|
|
82
|
+
left: (error: L) => R3;
|
|
83
83
|
}): Right<R2, never>;
|
|
84
84
|
matchMap<R2, R3 = R2>(this: Either<R, L>, op: {
|
|
85
85
|
right: (value: R) => R2;
|
|
86
|
-
left: (error:
|
|
86
|
+
left: (error: L) => R3;
|
|
87
87
|
}): Right<R2 | R3, never>;
|
|
88
88
|
/**
|
|
89
89
|
* Either composition function
|
|
@@ -135,75 +135,75 @@ export interface Right<R, L> {
|
|
|
135
135
|
*/
|
|
136
136
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
137
137
|
right: (value: R) => Right<R2, L2>;
|
|
138
|
-
left: (error:
|
|
138
|
+
left: (error: L) => Right<R3, L3>;
|
|
139
139
|
}): Right<R2, never>;
|
|
140
140
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
141
141
|
right: (value: R) => Left<R2, L2>;
|
|
142
|
-
left: (error:
|
|
142
|
+
left: (error: L) => Right<R3, L3>;
|
|
143
143
|
}): Left<never, L2>;
|
|
144
144
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
145
145
|
right: (value: R) => Right<R2, L2>;
|
|
146
|
-
left: (error:
|
|
146
|
+
left: (error: L) => Left<R3, L3>;
|
|
147
147
|
}): Right<R2, never>;
|
|
148
148
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
149
149
|
right: (value: R) => Left<R2, L2>;
|
|
150
|
-
left: (error:
|
|
150
|
+
left: (error: L) => Left<R3, L3>;
|
|
151
151
|
}): Left<never, L2>;
|
|
152
152
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
153
153
|
right: (value: R) => Either<R2, L2>;
|
|
154
|
-
left: (error:
|
|
154
|
+
left: (error: L) => Right<R3, L3>;
|
|
155
155
|
}): Either<R2, L2>;
|
|
156
156
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
157
157
|
right: (value: R) => Either<R2, L2>;
|
|
158
|
-
left: (error:
|
|
158
|
+
left: (error: L) => Left<R3, L3>;
|
|
159
159
|
}): Either<R2, L2>;
|
|
160
160
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
161
161
|
right: (value: R) => Right<R2, L2>;
|
|
162
|
-
left: (error:
|
|
162
|
+
left: (error: L) => Either<R3, L3>;
|
|
163
163
|
}): Right<R2, never>;
|
|
164
164
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
165
165
|
right: (value: R) => Left<R2, L2>;
|
|
166
|
-
left: (error:
|
|
166
|
+
left: (error: L) => Either<R3, L3>;
|
|
167
167
|
}): Left<never, L2>;
|
|
168
168
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
169
169
|
right: (value: R) => Either<R2, L2>;
|
|
170
|
-
left: (error:
|
|
170
|
+
left: (error: L) => Either<R3, L3>;
|
|
171
171
|
}): Either<R2, L2>;
|
|
172
172
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
173
173
|
right: (value: R) => Right<R2, L2>;
|
|
174
|
-
left: (error:
|
|
174
|
+
left: (error: L) => Right<R3, L3>;
|
|
175
175
|
}): Right<R2 | R3, never>;
|
|
176
176
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
177
177
|
right: (value: R) => Left<R2, L2>;
|
|
178
|
-
left: (error:
|
|
178
|
+
left: (error: L) => Right<R3, L3>;
|
|
179
179
|
}): Either<R3, L2>;
|
|
180
180
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
181
181
|
right: (value: R) => Right<R2, L2>;
|
|
182
|
-
left: (error:
|
|
182
|
+
left: (error: L) => Left<R3, L3>;
|
|
183
183
|
}): Either<R2, L3>;
|
|
184
184
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
185
185
|
right: (value: R) => Left<R2, L2>;
|
|
186
|
-
left: (error:
|
|
186
|
+
left: (error: L) => Left<R3, L3>;
|
|
187
187
|
}): Left<never, L2 | L3>;
|
|
188
188
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
189
189
|
right: (value: R) => Either<R2, L2>;
|
|
190
|
-
left: (error:
|
|
190
|
+
left: (error: L) => Right<R3, L3>;
|
|
191
191
|
}): Either<R2 | R3, L2>;
|
|
192
192
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
193
193
|
right: (value: R) => Either<R2, L2>;
|
|
194
|
-
left: (error:
|
|
194
|
+
left: (error: L) => Left<R3, L3>;
|
|
195
195
|
}): Either<R2, L2 | L3>;
|
|
196
196
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
197
197
|
right: (value: R) => Right<R2, L2>;
|
|
198
|
-
left: (error:
|
|
198
|
+
left: (error: L) => Either<R3, L3>;
|
|
199
199
|
}): Either<R2 | R3, L3>;
|
|
200
200
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
201
201
|
right: (value: R) => Left<R2, L2>;
|
|
202
|
-
left: (error:
|
|
202
|
+
left: (error: L) => Either<R3, L3>;
|
|
203
203
|
}): Either<R3, L2 | L3>;
|
|
204
204
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
205
205
|
right: (value: R) => Either<R2, L2>;
|
|
206
|
-
left: (error:
|
|
206
|
+
left: (error: L) => Either<R3, L3>;
|
|
207
207
|
}): Either<R2 | R3, L2 | L3>;
|
|
208
208
|
/**
|
|
209
209
|
* Either type guard for 'right'
|
|
@@ -231,6 +231,14 @@ export interface Right<R, L> {
|
|
|
231
231
|
* ```
|
|
232
232
|
*/
|
|
233
233
|
isLeft(): this is Left<R, L>;
|
|
234
|
+
/**
|
|
235
|
+
* Wrap Maybe to singleton generator
|
|
236
|
+
*
|
|
237
|
+
* Userful in order to avoid ambiguous yied types
|
|
238
|
+
*
|
|
239
|
+
* @returns generator of Maybe wrapping this
|
|
240
|
+
*/
|
|
241
|
+
generator: EitherGeneratorFunction<[], R, Right<R, L>, R>;
|
|
234
242
|
}
|
|
235
243
|
/**
|
|
236
244
|
* Left (erroneous) value of type L
|
|
@@ -274,7 +282,7 @@ export interface Left<R, L> {
|
|
|
274
282
|
*/
|
|
275
283
|
matchTap(op: {
|
|
276
284
|
right: (value: R) => void;
|
|
277
|
-
left: (error:
|
|
285
|
+
left: (error: L) => void;
|
|
278
286
|
}): this;
|
|
279
287
|
/**
|
|
280
288
|
* Either transformer function
|
|
@@ -313,11 +321,11 @@ export interface Left<R, L> {
|
|
|
313
321
|
*/
|
|
314
322
|
matchMap<R2, R3 = R2>(this: Left<R, L>, op: {
|
|
315
323
|
right: (value: R) => R2;
|
|
316
|
-
left: (error:
|
|
324
|
+
left: (error: L) => R3;
|
|
317
325
|
}): Right<R3, never>;
|
|
318
326
|
matchMap<R2, R3 = R2>(this: Either<R, L>, op: {
|
|
319
327
|
right: (value: R) => R2;
|
|
320
|
-
left: (error:
|
|
328
|
+
left: (error: L) => R3;
|
|
321
329
|
}): Right<R2 | R3, never>;
|
|
322
330
|
/**
|
|
323
331
|
* Either composition function
|
|
@@ -369,75 +377,75 @@ export interface Left<R, L> {
|
|
|
369
377
|
*/
|
|
370
378
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
371
379
|
right: (value: R) => Right<R2, L2>;
|
|
372
|
-
left: (error:
|
|
380
|
+
left: (error: L) => Right<R3, L3>;
|
|
373
381
|
}): Right<R3, never>;
|
|
374
382
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
375
383
|
right: (value: R) => Left<R2, L2>;
|
|
376
|
-
left: (error:
|
|
384
|
+
left: (error: L) => Right<R3, L3>;
|
|
377
385
|
}): Right<R3, never>;
|
|
378
386
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
379
387
|
right: (value: R) => Right<R2, L2>;
|
|
380
|
-
left: (error:
|
|
388
|
+
left: (error: L) => Left<R3, L3>;
|
|
381
389
|
}): Left<never, L3>;
|
|
382
390
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
383
391
|
right: (value: R) => Left<R2, L2>;
|
|
384
|
-
left: (error:
|
|
392
|
+
left: (error: L) => Left<R3, L3>;
|
|
385
393
|
}): Left<never, L3>;
|
|
386
394
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
387
395
|
right: (value: R) => Either<R2, L2>;
|
|
388
|
-
left: (error:
|
|
396
|
+
left: (error: L) => Right<R3, L3>;
|
|
389
397
|
}): Right<R3, never>;
|
|
390
398
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
391
399
|
right: (value: R) => Either<R2, L2>;
|
|
392
|
-
left: (error:
|
|
400
|
+
left: (error: L) => Left<R3, L3>;
|
|
393
401
|
}): Left<never, L3>;
|
|
394
402
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
395
403
|
right: (value: R) => Right<R2, L2>;
|
|
396
|
-
left: (error:
|
|
404
|
+
left: (error: L) => Either<R3, L3>;
|
|
397
405
|
}): Either<R3, L3>;
|
|
398
406
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
399
407
|
right: (value: R) => Left<R2, L2>;
|
|
400
|
-
left: (error:
|
|
408
|
+
left: (error: L) => Either<R3, L3>;
|
|
401
409
|
}): Either<R3, L3>;
|
|
402
410
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
403
411
|
right: (value: R) => Either<R2, L2>;
|
|
404
|
-
left: (error:
|
|
412
|
+
left: (error: L) => Either<R3, L3>;
|
|
405
413
|
}): Either<R3, L3>;
|
|
406
414
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
407
415
|
right: (value: R) => Right<R2, L2>;
|
|
408
|
-
left: (error:
|
|
416
|
+
left: (error: L) => Right<R3, L3>;
|
|
409
417
|
}): Right<R2 | R3, never>;
|
|
410
418
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
411
419
|
right: (value: R) => Left<R2, L2>;
|
|
412
|
-
left: (error:
|
|
420
|
+
left: (error: L) => Right<R3, L3>;
|
|
413
421
|
}): Either<R3, L2>;
|
|
414
422
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
415
423
|
right: (value: R) => Right<R2, L2>;
|
|
416
|
-
left: (error:
|
|
424
|
+
left: (error: L) => Left<R3, L3>;
|
|
417
425
|
}): Either<R2, L3>;
|
|
418
426
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
419
427
|
right: (value: R) => Left<R2, L2>;
|
|
420
|
-
left: (error:
|
|
428
|
+
left: (error: L) => Left<R3, L3>;
|
|
421
429
|
}): Left<never, L2 | L3>;
|
|
422
430
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
423
431
|
right: (value: R) => Either<R2, L2>;
|
|
424
|
-
left: (error:
|
|
432
|
+
left: (error: L) => Right<R3, L3>;
|
|
425
433
|
}): Either<R2 | R3, L2>;
|
|
426
434
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
427
435
|
right: (value: R) => Either<R2, L2>;
|
|
428
|
-
left: (error:
|
|
436
|
+
left: (error: L) => Left<R3, L3>;
|
|
429
437
|
}): Either<R2, L2 | L3>;
|
|
430
438
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
431
439
|
right: (value: R) => Right<R2, L2>;
|
|
432
|
-
left: (error:
|
|
440
|
+
left: (error: L) => Either<R3, L3>;
|
|
433
441
|
}): Either<R2 | R3, L3>;
|
|
434
442
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
435
443
|
right: (value: R) => Left<R2, L2>;
|
|
436
|
-
left: (error:
|
|
444
|
+
left: (error: L) => Either<R3, L3>;
|
|
437
445
|
}): Either<R3, L2 | L3>;
|
|
438
446
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Either<R, L>, op: {
|
|
439
447
|
right: (value: R) => Either<R2, L2>;
|
|
440
|
-
left: (error:
|
|
448
|
+
left: (error: L) => Either<R3, L3>;
|
|
441
449
|
}): Either<R2 | R3, L2 | L3>;
|
|
442
450
|
/**
|
|
443
451
|
* Either type guard for 'right'
|
|
@@ -465,6 +473,14 @@ export interface Left<R, L> {
|
|
|
465
473
|
* ```
|
|
466
474
|
*/
|
|
467
475
|
isLeft(): this is Left<R, L>;
|
|
476
|
+
/**
|
|
477
|
+
* Wrap Maybe to singleton generator
|
|
478
|
+
*
|
|
479
|
+
* Userful in order to avoid ambiguous yied types
|
|
480
|
+
*
|
|
481
|
+
* @returns generator of Maybe wrapping this
|
|
482
|
+
*/
|
|
483
|
+
generator: EitherGeneratorFunction<[], R, Left<R, L>, R>;
|
|
468
484
|
}
|
|
469
485
|
/**
|
|
470
486
|
* Either data type: either Right value of type R or Left value of type L
|
|
@@ -502,6 +518,8 @@ export declare namespace Left {
|
|
|
502
518
|
*/
|
|
503
519
|
function left<R, L>(left: Left<R, L>): L;
|
|
504
520
|
}
|
|
521
|
+
export declare type EitherGenerator<T, TT extends Either<T, any>, R> = Generator<TT, R, T>;
|
|
522
|
+
export declare type EitherGeneratorFunction<A extends unknown[], T, TT extends Either<T, any>, R> = (...args: A) => EitherGenerator<T, TT, R>;
|
|
505
523
|
export declare namespace Either {
|
|
506
524
|
/**
|
|
507
525
|
* Right monad constructor
|
|
@@ -577,7 +595,7 @@ export declare namespace Either {
|
|
|
577
595
|
* @param eithers a list of Either
|
|
578
596
|
* @returns true in case at least one list element is Right
|
|
579
597
|
*/
|
|
580
|
-
function someRight<R, L>(eithers: Either<R, L>[]):
|
|
598
|
+
function someRight<R, L>(eithers: Either<R, L>[]): boolean;
|
|
581
599
|
/**
|
|
582
600
|
* Standalone list predicate
|
|
583
601
|
*
|
|
@@ -591,5 +609,18 @@ export declare namespace Either {
|
|
|
591
609
|
* @param eithers a list of Either
|
|
592
610
|
* @returns true in case at least one list element is Left
|
|
593
611
|
*/
|
|
594
|
-
function someLeft<R, L>(eithers: Either<R, L>[]):
|
|
612
|
+
function someLeft<R, L>(eithers: Either<R, L>[]): boolean;
|
|
613
|
+
/**
|
|
614
|
+
* Create compound Either from generator function
|
|
615
|
+
*
|
|
616
|
+
* Applying yield to a Maybe within the generator function unwraps the Maybe and returns underlying value in case of success
|
|
617
|
+
* However the convinient option for typescript is to use ```yield* maybe.generator()``` as othervise one may have to deal with union types
|
|
618
|
+
*
|
|
619
|
+
* @template TT yielded Maybe type
|
|
620
|
+
* @template R returned underlying type
|
|
621
|
+
* @param maybeGeneratorFunction Maybe generator function
|
|
622
|
+
* @returns Just wrapping the result of generator function or Nothing
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
function generate<T, TT extends Either<T, any>, R>(eitherGeneratorFunction: EitherGeneratorFunction<[], T, TT, R>): Either<R, any>;
|
|
595
626
|
}
|
package/dist/maybe.d.ts
CHANGED
|
@@ -226,6 +226,14 @@ export interface Just<R> {
|
|
|
226
226
|
* ```
|
|
227
227
|
*/
|
|
228
228
|
isNothing(): this is Nothing<R>;
|
|
229
|
+
/**
|
|
230
|
+
* Wrap Maybe to singleton generator
|
|
231
|
+
*
|
|
232
|
+
* Userful in order to avoid ambiguous yied types
|
|
233
|
+
*
|
|
234
|
+
* @returns generator of Maybe wrapping this
|
|
235
|
+
*/
|
|
236
|
+
generator: MaybeGeneratorFunction<[], R, Just<R>, R>;
|
|
229
237
|
}
|
|
230
238
|
/**
|
|
231
239
|
* Absolutely Nothing
|
|
@@ -452,6 +460,14 @@ export interface Nothing<R> {
|
|
|
452
460
|
* ```
|
|
453
461
|
*/
|
|
454
462
|
isNothing(): this is Nothing<R>;
|
|
463
|
+
/**
|
|
464
|
+
* Wrap Maybe to singleton generator
|
|
465
|
+
*
|
|
466
|
+
* Userful in order to avoid ambiguous yied types
|
|
467
|
+
*
|
|
468
|
+
* @returns generator of Maybe wrapping this
|
|
469
|
+
*/
|
|
470
|
+
generator: MaybeGeneratorFunction<[], R, Nothing<R>, R>;
|
|
455
471
|
}
|
|
456
472
|
/**
|
|
457
473
|
* Genric Maybe monad interface
|
|
@@ -475,6 +491,8 @@ export declare namespace Just {
|
|
|
475
491
|
function just<R>(just: Just<R>): R;
|
|
476
492
|
}
|
|
477
493
|
export declare namespace Nothing { }
|
|
494
|
+
export declare type MaybeGenerator<T, TT extends Maybe<T>, R> = Generator<TT, R, T>;
|
|
495
|
+
export declare type MaybeGeneratorFunction<A extends unknown[], T, TT extends Maybe<T>, R> = (...args: A) => MaybeGenerator<T, TT, R>;
|
|
478
496
|
export declare namespace Maybe {
|
|
479
497
|
/**
|
|
480
498
|
* Non-empty monad constructor
|
|
@@ -546,7 +564,7 @@ export declare namespace Maybe {
|
|
|
546
564
|
* @param maybes a list of Maybe
|
|
547
565
|
* @returns true in case al east one list element is Just
|
|
548
566
|
*/
|
|
549
|
-
function someJust<R>(maybes: Maybe<R>[]):
|
|
567
|
+
function someJust<R>(maybes: Maybe<R>[]): boolean;
|
|
550
568
|
/**
|
|
551
569
|
* Standalone list predicate
|
|
552
570
|
*
|
|
@@ -560,5 +578,18 @@ export declare namespace Maybe {
|
|
|
560
578
|
* @param maybes a list of Maybe
|
|
561
579
|
* @returns true in case at least one list element is Nothing
|
|
562
580
|
*/
|
|
563
|
-
function someNothing<R>(maybes: Maybe<R>[]):
|
|
581
|
+
function someNothing<R>(maybes: Maybe<R>[]): boolean;
|
|
582
|
+
/**
|
|
583
|
+
* Create compound Maybe from generator function
|
|
584
|
+
*
|
|
585
|
+
* Applying yield to a Maybe within the generator function unwraps the Maybe and returns underlying value in case of success
|
|
586
|
+
* However the convinient option for typescript is to use ```yield* maybe.generator()``` as othervise one may have to deal with union types
|
|
587
|
+
*
|
|
588
|
+
* @template TT yielded Maybe type
|
|
589
|
+
* @template R returned underlying type
|
|
590
|
+
* @param maybeGeneratorFunction Maybe generator function
|
|
591
|
+
* @returns Just wrapping the result of generator function or Nothing
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
function generate<T, TT extends Maybe<T>, R>(maybeGeneratorFunction: MaybeGeneratorFunction<[], T, TT, R>): Maybe<R>;
|
|
564
595
|
}
|
package/dist/t-tasks.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t,
|
|
1
|
+
var t,e;!function(t){t.just=function(t){return t.just}}(t||(t={})),function(t){t.just=function(t){return new r(t)},t.nothing=function(){return n},t.fromOptional=function(e){return void 0!==e?t.just(e):t.nothing()},t.fromNullable=function(e){return t.fromOptional(e).chain(e=>null!==e?t.just(e):t.nothing())},t.isJust=function(t){return t.isJust()},t.isNothing=function(t){return t.isNothing()},t.everyJust=function(e){return e.every(t.isJust)},t.someJust=function(e){return e.some(t.isJust)},t.everyNothing=function(e){return e.every(t.isNothing)},t.someNothing=function(e){return e.some(t.isNothing)},t.generate=function(e){const r=e(),n=e=>e.done?t.just(e.value):e.value.matchChain({just:t=>n(r.next(t)),nothing:t.nothing});return t.just(void 0).chain(()=>n(r.next()))}}(e||(e={}));class r{constructor(t){this.just=void 0,this.just=t}tap(t){return t(this.just),this}orTap(){return this}map(t){return e.just(t(this.just))}orMap(){return this}chain(t){return t(this.just)}orChain(){return this}isJust(){return!0}isNothing(){return!1}matchTap(t){return this.tap(t.just)}matchMap(t){return this.map(t.just)}matchChain(t){return this.chain(t.just)}generator(){/*#__PURE__*/return regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)})(this)}}const n=new class{tap(){return this}orTap(t){return t(),this}map(){return this}orMap(t){return e.just(t())}chain(){return this}orChain(t){return t()}isJust(){return!1}isNothing(){return!0}matchTap(t){return this.orTap(t.nothing)}matchMap(t){return this.orMap(t.nothing)}matchChain(t){return this.orChain(t.nothing)}generator(){/*#__PURE__*/return regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)})(this)}};var i,u,o,a;!function(t){t.right=function(t){return t.right}}(i||(i={})),function(t){t.left=function(t){return t.left}}(u||(u={})),function(t){t.right=function(t){return new c(t)},t.left=function(t){return new s(t)},t.fromOptional=function(e,r){return void 0!==e?t.right(e):t.left(r)},t.fromNullable=function(e,r){return t.fromOptional(e,r).chain(n=>null!==n?t.right(e):t.left(r))},t.isRight=function(t){return t.isRight()},t.isLeft=function(t){return t.isLeft()},t.everyRight=function(e){return e.every(t.isRight)},t.someRight=function(e){return e.some(t.isRight)},t.everyLeft=function(e){return e.every(t.isLeft)},t.someLeft=function(e){return e.some(t.isLeft)},t.generate=function(e){const r=e(),n=e=>e.done?t.right(e.value):e.value.matchChain({right:t=>n(r.next(t)),left:t.left});return t.right(void 0).chain(()=>n(r.next()))}}(o||(o={}));class c{constructor(t){this.right=void 0,this.right=t}tap(t){return t(this.right),this}orTap(){return this}map(t){return o.right(t(this.right))}orMap(){return this}chain(t){return t(this.right)}orChain(){return this}isRight(){return!0}isLeft(){return!1}matchTap(t){return this.tap(t.right)}matchMap(t){return this.map(t.right)}matchChain(t){return this.chain(t.right)}generator(){/*#__PURE__*/return regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)})(this)}}class s{constructor(t){this.left=void 0,this.left=t}tap(){return this}orTap(t){return t(this.left),this}map(){return this}orMap(t){return o.right(t(this.left))}chain(){return this}orChain(t){return t(this.left)}isRight(){return!1}isLeft(){return!0}matchTap(t){return this.orTap(t.left)}matchMap(t){return this.orMap(t.left)}matchChain(t){return this.orChain(t.left)}generator(){/*#__PURE__*/return regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)})(this)}}!function(r){function n(t,n){let i;const[u,a]=h();return r.create(new Promise(r=>{a(r),i=t(t=>u(e.just(o.right(t))),t=>u(e.just(o.left(t))))}),t=>{u(t.map(o.left)),n(i)})}r.create=function(t,e){return new d(t,e)},r.resolved=function(t){return r.create(Promise.resolve(e.just(o.right(t))),()=>{})},r.rejected=function(t){return r.create(Promise.resolve(e.just(o.left(t))),()=>{})},r.canceled=function(){return r.create(Promise.resolve(e.nothing()),()=>{})},r.fromPromise=function(t){const[n,i]=h();return r.create(new Promise(r=>{i(r),t.then(o.right,o.left).then(e.just).then(n)}),t=>n(t.map(o.left)))},r.fromFunction=function(t,n){const[i,u]=h(),a=t=>i(t.map(o.left));return n.cancel=a,r.create(new Promise(r=>{u(r);try{i(e.just(o.right(t())))}catch(t){i(e.just(o.left(t)))}}),a)},r.promiseGenerator=function(t){return r.fromPromise(t).generator()},r.timeoutGenerator=function(t){return r.timeout(t).generator()},r.lift=function(t){return function(){return r.fromPromise(t(...[].slice.call(arguments)))}},r.generate=function(t){const e=t(),n=t=>t.done?r.resolved(t.value):t.value.matchChain({resolved:t=>n(e.next(t)),rejected:t=>n(e.throw(t)),canceled:r.canceled});return r.resolved(void 0).chain(()=>n(e.next()))},r.timeout=function(t){return n(e=>setTimeout(()=>e(),t),clearTimeout)},r.fromCallback=n,r.sequence=function(t){return Array.from(t).reduce((t,e)=>t.chain(t=>e().map(e=>t.concat(e))),r.resolved([]))},r.all=function(n){const[i,u]=h(),a=Array.from(n),c=t=>a.forEach(e=>e._cancel(t)),s=a.map(e.nothing),f=t=>{i(t.map(o.left)),c(t)};return r.create(new Promise(r=>{if(u(r),a.length<1)return i(e.just(o.right([])));a.map((r,n)=>r.matchTap({resolved:r=>((r,n)=>{s[n]=e.just(r),e.everyJust(s)&&i(e.just(o.right(s.map(t.just))))})(r,n),rejected:t=>f(e.just(t)),canceled:()=>f(e.nothing())}))}),c)},r.any=function(n){const[i,u]=h(),a=Array.from(n),c=t=>a.forEach(e=>e._cancel(t)),s=a.map(e.nothing),f=t=>{i(t.map(o.right)),c(e.nothing())};return r.create(new Promise(r=>{if(u(r),a.length<1)return i(e.nothing());a.map((r,n)=>r.matchTap({resolved:t=>f(e.just(t)),rejected:r=>((r,n)=>{s[n]=e.just(r),e.everyJust(s)&&i(e.just(o.left(s.map(t.just))))})(r,n),canceled:()=>f(e.nothing())}))}),c)},r.limit=function(t,e){return r.any([t,e.chain(r.canceled)]).chainRejected(t=>r.rejected(t[0]))},r.repeat=function(t){const e=()=>t().chainRejected(e);return e()}}(a||(a={}));const h=()=>{const t=()=>{};let e=t;return[r=>{const n=e;e=t,n(r)},t=>{e=t}]};function f(t,r){const n={cancel:t._cancel};return a.create(t._invoke.then(function(t){try{return Promise.resolve(function(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(function(){const{_invoke:i,_cancel:u}=a.fromFunction(()=>r(t),n);return n.cancel=u,Promise.resolve(i).then(function(t){if(t.isNothing())return e.nothing();if(t.just.isLeft())return e.just(o.left(t.just.left));const{_invoke:r,_cancel:i}=t.just.right;return n.cancel=i,r})},function(t){return e.just(o.left(t))}))}catch(t){return Promise.reject(t)}}),t=>n.cancel(t))}function l(t,e){return f(t,t=>t.map(e).orMap(a.canceled).just)}function m(t,e){return f(t,t=>e(t).matchMap({just:t=>t.matchMap({right:a.resolved,left:a.rejected}).right,nothing:a.canceled}).just)}function p(t,e){return m(t,t=>t.map(e))}function g(t,e){return m(t,t=>(e(t),t))}function j(t,e){return g(t,t=>t.tap(e))}class d{constructor(t,e){this._invoke=void 0,this._cancel=void 0,this._invoke=t,this._cancel=e}tapCanceled(t){return g(this,e=>e.orTap(t))}tapRejected(t){return j(this,e=>e.orTap(t))}tap(t){return j(this,e=>e.tap(t))}mapCanceled(t){return m(this,e=>e.orMap(()=>o.right(t())))}mapRejected(t){return p(this,e=>e.orMap(t))}map(t){return p(this,e=>e.map(t))}chainCanceled(t){const e=t=>t.map(a.resolved).orMap(a.rejected).right;return f(this,r=>r.map(e).orMap(t).just)}chainRejected(t){return l(this,e=>e.map(a.resolved).orMap(t).right)}chain(t){return l(this,e=>e.map(t).orMap(a.rejected).right)}resolve(){return this._invoke}cancel(){return this._cancel(e.nothing())}reject(t){return this._cancel(e.just(t))}generator(){/*#__PURE__*/return regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e;case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)})(this)}matchTap(t){return g(this,e=>e.matchTap({just:e=>e.matchTap({right:t.resolved,left:t.rejected}),nothing:t.canceled}))}matchMap(t){return m(this,e=>e.matchMap({just:e=>e.matchMap({right:t.resolved,left:t.rejected}),nothing:()=>o.right(t.canceled())}))}matchChain(t){return f(this,e=>e.matchMap({just:e=>e.matchMap({right:t.resolved,left:t.rejected}).right,nothing:t.canceled}).just)}}export{o as Either,t as Just,u as Left,e as Maybe,i as Right,a as Task};
|
|
2
2
|
//# sourceMappingURL=t-tasks.esm.js.map
|