t-tasks 2.0.0 → 2.1.1
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/t-tasks.d.ts +144 -21
- package/dist/t-tasks.esm.js +72 -37
- package/dist/t-tasks.esm.js.map +1 -1
- package/dist/t-tasks.js +72 -37
- package/dist/t-tasks.js.map +1 -1
- package/package.json +1 -1
- package/src/either.ts +62 -5
- package/src/maybe.ts +54 -3
- package/src/task.ts +142 -76
package/src/either.ts
CHANGED
|
@@ -64,6 +64,7 @@ export interface Right<R, L> {
|
|
|
64
64
|
* Applied to 'right value' returns self without invoking transformer
|
|
65
65
|
* Applied to 'left error' returns 'right op(error)'
|
|
66
66
|
*
|
|
67
|
+
* @template R2 transformer function's return type
|
|
67
68
|
* @param op transformer to be invoked with underlying error
|
|
68
69
|
* @returns 'right value' or 'right op(error)'
|
|
69
70
|
*/
|
|
@@ -89,6 +90,18 @@ export interface Right<R, L> {
|
|
|
89
90
|
// General case
|
|
90
91
|
match<R2, R3 = R2>(this: Either<R, L>, op: { right: (value: R) => R2; left: (error: L) => R3 }): R2 | R3;
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Either pattern matching transformer function
|
|
95
|
+
*
|
|
96
|
+
* Applied to 'right value' returns 'right op.right(value)'
|
|
97
|
+
* Applied to 'left error' returns 'right op.left(error)'
|
|
98
|
+
*
|
|
99
|
+
* @template R2 right transformer function's return type
|
|
100
|
+
* @template R3 left transformer function's return type
|
|
101
|
+
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
102
|
+
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
103
|
+
* @returns 'right op.right(value)' or 'right op.left(error)'
|
|
104
|
+
*/
|
|
92
105
|
// Right case
|
|
93
106
|
matchMap<R2, R3 = R2>(this: Right<R, L>, op: { right: (value: R) => R2; left: (error: L) => R3 }): Right<R2, never>;
|
|
94
107
|
// General case
|
|
@@ -115,7 +128,7 @@ export interface Right<R, L> {
|
|
|
115
128
|
chain<R2, L2>(this: Either<R, L>, op: (value: R) => Either<R2, L2>): Either<R2, L | L2>;
|
|
116
129
|
|
|
117
130
|
/**
|
|
118
|
-
* Either composition function
|
|
131
|
+
* Either fallback composition function
|
|
119
132
|
*
|
|
120
133
|
* Applied to 'right value' returns self without invoking composition function
|
|
121
134
|
* Applied to 'left error' returns 'op(error)'
|
|
@@ -146,7 +159,7 @@ export interface Right<R, L> {
|
|
|
146
159
|
* @template L3 left transformer function result's underlying error type
|
|
147
160
|
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
148
161
|
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
149
|
-
* @returns 'op(value)' or 'op(error)'
|
|
162
|
+
* @returns 'op.right(value)' or 'op.left(error)'
|
|
150
163
|
*/
|
|
151
164
|
// Right cases
|
|
152
165
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: { right: (value: R) => Right<R2, L2>; left: (error: L) => Right<R3, L3> }): Right<R2, never>;
|
|
@@ -273,6 +286,7 @@ export interface Left<R, L> {
|
|
|
273
286
|
* Applied to 'right value' returns self without invoking transformer
|
|
274
287
|
* Applied to 'left error' returns 'right op(error)'
|
|
275
288
|
*
|
|
289
|
+
* @template R2 transformer function's return type
|
|
276
290
|
* @param op transformer to be invoked with underlying error
|
|
277
291
|
* @returns 'right value' or 'right op(error)'
|
|
278
292
|
*/
|
|
@@ -298,6 +312,18 @@ export interface Left<R, L> {
|
|
|
298
312
|
// General case
|
|
299
313
|
match<R2, R3 = R2>(this: Either<R, L>, op: { right: (value: R) => R2; left: (error: L) => R3 }): R2 | R3;
|
|
300
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Either pattern matching transformer function
|
|
317
|
+
*
|
|
318
|
+
* Applied to 'right value' returns 'right op.right(value)'
|
|
319
|
+
* Applied to 'left error' returns 'right op.left(error)'
|
|
320
|
+
*
|
|
321
|
+
* @template R2 right transformer function's return type
|
|
322
|
+
* @template R3 left transformer function's return type
|
|
323
|
+
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
324
|
+
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
325
|
+
* @returns 'right op.right(value)' or 'right op.left(error)'
|
|
326
|
+
*/
|
|
301
327
|
// Left case
|
|
302
328
|
matchMap<R2, R3 = R2>(this: Left<R, L>, op: { right: (value: R) => R2; left: (error: L) => R3 }): Right<R3, never>;
|
|
303
329
|
// General case
|
|
@@ -355,7 +381,7 @@ export interface Left<R, L> {
|
|
|
355
381
|
* @template L3 left transformer function result's underlying error type
|
|
356
382
|
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
357
383
|
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
358
|
-
* @returns 'op(value)' or 'op(error)'
|
|
384
|
+
* @returns 'op.right(value)' or 'op.left(error)'
|
|
359
385
|
*/
|
|
360
386
|
// Left cases
|
|
361
387
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: { right: (value: R) => Right<R2, L2>; left: (error: L) => Right<R3, L3> }): Right<R3, never>;
|
|
@@ -459,7 +485,23 @@ export namespace Left {
|
|
|
459
485
|
}
|
|
460
486
|
}
|
|
461
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Either generator
|
|
490
|
+
*
|
|
491
|
+
* @template T yielded underlying type
|
|
492
|
+
* @template TT yielded Either type
|
|
493
|
+
* @template R returned underlying type
|
|
494
|
+
*/
|
|
462
495
|
export type EitherGenerator<T, TT extends Either<T, any>, R> = Generator<TT, R, T>;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Function returning Either generator (generator function)
|
|
499
|
+
*
|
|
500
|
+
* @template A argument types
|
|
501
|
+
* @template T yielded underlying type
|
|
502
|
+
* @template TT yielded Either type
|
|
503
|
+
* @template R returned underlying type
|
|
504
|
+
*/
|
|
463
505
|
export type EitherGeneratorFunction<A extends unknown[], T, TT extends Either<T, any>, R> = (...args: A) => EitherGenerator<T, TT, R>;
|
|
464
506
|
|
|
465
507
|
export namespace Either {
|
|
@@ -490,6 +532,8 @@ export namespace Either {
|
|
|
490
532
|
*
|
|
491
533
|
* Resolves to 'left error' in case of undefined value and 'right value' otherwise
|
|
492
534
|
*
|
|
535
|
+
* @template R underlying value type
|
|
536
|
+
* @template L underlying error type
|
|
493
537
|
* @param value possibly undefined value
|
|
494
538
|
* @param error error to use in case of undefined value
|
|
495
539
|
* @returns either 'right value' or 'left error'
|
|
@@ -506,8 +550,10 @@ export namespace Either {
|
|
|
506
550
|
*
|
|
507
551
|
* Resolves to 'left error' in case of undefined or null value and 'right value' otherwise
|
|
508
552
|
*
|
|
509
|
-
* @
|
|
510
|
-
* @
|
|
553
|
+
* @template R underlying value type
|
|
554
|
+
* @template L underlying error type
|
|
555
|
+
* @param value possibly undefined or null value
|
|
556
|
+
* @param error error to use in case of undefined or null value
|
|
511
557
|
* @returns either 'right value' or 'left error'
|
|
512
558
|
*/
|
|
513
559
|
export function fromNullable<L>(value: undefined, error: L): Left<never, L>;
|
|
@@ -544,6 +590,7 @@ export namespace Either {
|
|
|
544
590
|
* Useful for passing as a predicate to collection transformers
|
|
545
591
|
*
|
|
546
592
|
* @template R underlying value type
|
|
593
|
+
* @template L underlying error type
|
|
547
594
|
* @param either Either instance
|
|
548
595
|
* @returns 'true' in case argument is 'right value' (and resolves type to be 'right')
|
|
549
596
|
*/
|
|
@@ -557,6 +604,7 @@ export namespace Either {
|
|
|
557
604
|
* Useful for passing as a predicate to collection transformers
|
|
558
605
|
*
|
|
559
606
|
* @template R underlying value type
|
|
607
|
+
* @template L underlying error type
|
|
560
608
|
* @param either Either instance
|
|
561
609
|
* @returns 'true' in case argument is 'left error' (and resolves type to be 'left')
|
|
562
610
|
*/
|
|
@@ -567,6 +615,8 @@ export namespace Either {
|
|
|
567
615
|
/**
|
|
568
616
|
* Standalone list predicate
|
|
569
617
|
*
|
|
618
|
+
* @template R underlying value type
|
|
619
|
+
* @template L underlying error type
|
|
570
620
|
* @param eithers a list of Either
|
|
571
621
|
* @returns true in case every list element is Right
|
|
572
622
|
*/
|
|
@@ -577,6 +627,8 @@ export namespace Either {
|
|
|
577
627
|
/**
|
|
578
628
|
* Standalone list predicate
|
|
579
629
|
*
|
|
630
|
+
* @template R underlying value type
|
|
631
|
+
* @template L underlying error type
|
|
580
632
|
* @param eithers a list of Either
|
|
581
633
|
* @returns true in case at least one list element is Right
|
|
582
634
|
*/
|
|
@@ -587,6 +639,8 @@ export namespace Either {
|
|
|
587
639
|
/**
|
|
588
640
|
* Standalone list predicate
|
|
589
641
|
*
|
|
642
|
+
* @template R underlying value type
|
|
643
|
+
* @template L underlying error type
|
|
590
644
|
* @param eithers a list of Either
|
|
591
645
|
* @returns true in case every list element is Left
|
|
592
646
|
*/
|
|
@@ -597,6 +651,8 @@ export namespace Either {
|
|
|
597
651
|
/**
|
|
598
652
|
* Standalone list predicate
|
|
599
653
|
*
|
|
654
|
+
* @template R underlying value type
|
|
655
|
+
* @template L underlying error type
|
|
600
656
|
* @param eithers a list of Either
|
|
601
657
|
* @returns true in case at least one list element is Left
|
|
602
658
|
*/
|
|
@@ -610,6 +666,7 @@ export namespace Either {
|
|
|
610
666
|
* Applying yield to an Either within the generator function unwraps the Either and returns underlying value in case of success
|
|
611
667
|
* However the convenient option for typescript is to use ```yield* either.generator()``` as otherwise one may have to deal with union types
|
|
612
668
|
*
|
|
669
|
+
* @template T yielded underlying type
|
|
613
670
|
* @template TT yielded Either type
|
|
614
671
|
* @template R returned underlying type
|
|
615
672
|
* @param eitherGeneratorFunction Either generator function
|
package/src/maybe.ts
CHANGED
|
@@ -63,6 +63,7 @@ export interface Just<R> {
|
|
|
63
63
|
* Applied to 'just value' returns self without invoking transformer
|
|
64
64
|
* Applied to 'nothing' returns 'just op()'
|
|
65
65
|
*
|
|
66
|
+
* @template R2 transformer function's return type
|
|
66
67
|
* @param op function to be invoked
|
|
67
68
|
* @returns 'just value' or 'just op()'
|
|
68
69
|
*/
|
|
@@ -88,7 +89,19 @@ export interface Just<R> {
|
|
|
88
89
|
// General case
|
|
89
90
|
match<R2, R3 = R2>(this: Maybe<R>, op: { just: (value: R) => R2; nothing: () => R3 }): R2 | R3;
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Maybe pattern matching transformer function
|
|
94
|
+
*
|
|
95
|
+
* Applied to 'just value' returns 'just op.just(value)'
|
|
96
|
+
* Applied to 'nothing' returns 'just op.nothing()'
|
|
97
|
+
*
|
|
98
|
+
* @template R2 just transformer function's return type
|
|
99
|
+
* @template R3 nothing transformer function's return type
|
|
100
|
+
* @param op.just transformer to be invoked with underlying value in case of just
|
|
101
|
+
* @param op.nothing transformer to be invoked in case of nothing
|
|
102
|
+
* @returns 'just op.just(value)' or 'just op.nothing()'
|
|
103
|
+
*/
|
|
104
|
+
// Just cases
|
|
92
105
|
matchMap<R2, R3 = R2>(this: Just<R>, op: { just: (value: R) => R2; nothing: () => R3 }): Just<R2>;
|
|
93
106
|
// General case
|
|
94
107
|
matchMap<R2, R3 = R2>(this: Maybe<R>, op: { just: (value: R) => R2; nothing: () => R3 }): Just<R2 | R3>;
|
|
@@ -207,6 +220,8 @@ export interface Just<R> {
|
|
|
207
220
|
* Absolutely Nothing
|
|
208
221
|
*
|
|
209
222
|
* Maybe data type specialization representing an absence of any value
|
|
223
|
+
*
|
|
224
|
+
* @template R underlying value
|
|
210
225
|
*/
|
|
211
226
|
export interface Nothing<R> {
|
|
212
227
|
/**
|
|
@@ -264,6 +279,7 @@ export interface Nothing<R> {
|
|
|
264
279
|
* Applied to 'just value' returns self without invoking transformer
|
|
265
280
|
* Applied to 'nothing' returns 'just op()'
|
|
266
281
|
*
|
|
282
|
+
* @template R2 transformer function's return type
|
|
267
283
|
* @param op function to be invoked
|
|
268
284
|
* @returns 'just value' or 'just op()'
|
|
269
285
|
*/
|
|
@@ -289,7 +305,19 @@ export interface Nothing<R> {
|
|
|
289
305
|
// General case
|
|
290
306
|
match<R2, R3 = R2>(this: Maybe<R>, op: { just: (value: R) => R2; nothing: () => R3 }): R2 | R3;
|
|
291
307
|
|
|
292
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Maybe pattern matching transformer function
|
|
310
|
+
*
|
|
311
|
+
* Applied to 'just value' returns 'just op.just(value)'
|
|
312
|
+
* Applied to 'nothing' returns 'just op.nothing()'
|
|
313
|
+
*
|
|
314
|
+
* @template R2 just transformer function's return type
|
|
315
|
+
* @template R3 nothing transformer function's return type
|
|
316
|
+
* @param op.just transformer to be invoked with underlying value in case of just
|
|
317
|
+
* @param op.nothing transformer to be invoked in case of nothing
|
|
318
|
+
* @returns 'just op.just(value)' or 'just op.nothing()'
|
|
319
|
+
*/
|
|
320
|
+
// Nothing cases
|
|
293
321
|
matchMap<R2, R3 = R2>(this: Nothing<R>, op: { just: (value: R) => R2; nothing: () => R3 }): Just<R3>;
|
|
294
322
|
// General case
|
|
295
323
|
matchMap<R2, R3 = R2>(this: Maybe<R>, op: { just: (value: R) => R2; nothing: () => R3 }): Just<R2 | R3>;
|
|
@@ -430,7 +458,23 @@ export namespace Just {
|
|
|
430
458
|
|
|
431
459
|
export namespace Nothing {}
|
|
432
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Maybe generator
|
|
463
|
+
*
|
|
464
|
+
* @template T yielded underlying type
|
|
465
|
+
* @template TT yielded Maybe type
|
|
466
|
+
* @template R returned underlying type
|
|
467
|
+
*/
|
|
433
468
|
export type MaybeGenerator<T, TT extends Maybe<T>, R> = Generator<TT, R, T>;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Function returning Maybe generator (generator function)
|
|
472
|
+
*
|
|
473
|
+
* @template A argument types
|
|
474
|
+
* @template T yielded underlying type
|
|
475
|
+
* @template TT yielded Maybe type
|
|
476
|
+
* @template R returned underlying type
|
|
477
|
+
*/
|
|
434
478
|
export type MaybeGeneratorFunction<A extends unknown[], T, TT extends Maybe<T>, R> = (...args: A) => MaybeGenerator<T, TT, R>;
|
|
435
479
|
|
|
436
480
|
export namespace Maybe {
|
|
@@ -459,6 +503,7 @@ export namespace Maybe {
|
|
|
459
503
|
*
|
|
460
504
|
* Resolves to 'nothing' in case of undefined value and 'just value' otherwise
|
|
461
505
|
*
|
|
506
|
+
* @template R underlying type
|
|
462
507
|
* @param value possibly undefined value
|
|
463
508
|
* @returns either 'just value' or 'nothing'
|
|
464
509
|
*/
|
|
@@ -474,7 +519,8 @@ export namespace Maybe {
|
|
|
474
519
|
*
|
|
475
520
|
* Resolves to 'nothing' in case of undefined or null value and 'just value' otherwise
|
|
476
521
|
*
|
|
477
|
-
* @
|
|
522
|
+
* @template R underlying type
|
|
523
|
+
* @param value possibly undefined or null value
|
|
478
524
|
* @returns either 'just value' or 'nothing'
|
|
479
525
|
*/
|
|
480
526
|
export function fromNullable(value: undefined): Nothing<never>;
|
|
@@ -533,6 +579,7 @@ export namespace Maybe {
|
|
|
533
579
|
/**
|
|
534
580
|
* Standalone list predicate
|
|
535
581
|
*
|
|
582
|
+
* @template R underlying value type
|
|
536
583
|
* @param maybes a list of Maybe
|
|
537
584
|
* @returns true in case every list element is Just
|
|
538
585
|
*/
|
|
@@ -543,6 +590,7 @@ export namespace Maybe {
|
|
|
543
590
|
/**
|
|
544
591
|
* Standalone list predicate
|
|
545
592
|
*
|
|
593
|
+
* @template R underlying value type
|
|
546
594
|
* @param maybes a list of Maybe
|
|
547
595
|
* @returns true in case at least one list element is Just
|
|
548
596
|
*/
|
|
@@ -553,6 +601,7 @@ export namespace Maybe {
|
|
|
553
601
|
/**
|
|
554
602
|
* Standalone list predicate
|
|
555
603
|
*
|
|
604
|
+
* @template R underlying value type
|
|
556
605
|
* @param maybes a list of Maybe
|
|
557
606
|
* @returns true in case every list element is Nothing
|
|
558
607
|
*/
|
|
@@ -563,6 +612,7 @@ export namespace Maybe {
|
|
|
563
612
|
/**
|
|
564
613
|
* Standalone list predicate
|
|
565
614
|
*
|
|
615
|
+
* @template R underlying value type
|
|
566
616
|
* @param maybes a list of Maybe
|
|
567
617
|
* @returns true in case at least one list element is Nothing
|
|
568
618
|
*/
|
|
@@ -576,6 +626,7 @@ export namespace Maybe {
|
|
|
576
626
|
* Applying yield to a Maybe within the generator function unwraps the Maybe and returns underlying value in case of success
|
|
577
627
|
* However the convenient option for typescript is to use ```yield* maybe.generator()``` as otherwise one may have to deal with union types
|
|
578
628
|
*
|
|
629
|
+
* @template T yielded underlying type
|
|
579
630
|
* @template TT yielded Maybe type
|
|
580
631
|
* @template R returned underlying type
|
|
581
632
|
* @param maybeGeneratorFunction Maybe generator function
|