t-tasks 1.2.1 → 2.1.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/maybe.d.ts DELETED
@@ -1,595 +0,0 @@
1
- /**
2
- * Just a value
3
- *
4
- * Maybe data type specialization representing an existing value
5
- *
6
- * @template R underlying value
7
- */
8
- export interface Just<R> {
9
- readonly just: R;
10
- /**
11
- * Maybe peeker function
12
- *
13
- * Applied to 'just value' returns self invoking op(value) in process
14
- * Applied to 'nothing' returns self without invoking callback
15
- *
16
- * @param op function to be invoked with underlying value
17
- * @returns self
18
- */
19
- tap(op: (value: R) => void): this;
20
- /**
21
- * Maybe fallback peeker function
22
- *
23
- * Applied to 'just value' returns self without invoking callback
24
- * Applied to 'nothing' returns self invoking op() in process
25
- *
26
- * @param op function to be invoked
27
- * @returns self
28
- */
29
- orTap(op: () => void): this;
30
- /**
31
- * Maybe patter matching peeker function
32
- *
33
- * Applied to 'just value' returns self invoking op.just(value) in process
34
- * Applied to 'nothing' returns self invoking op.nothing() in process
35
- *
36
- * @param op.just function to be invoked with underlying value in case of just
37
- * @param op.nothing function to be invoked in case of nothing
38
- * @returns self
39
- */
40
- matchTap(op: {
41
- just: (value: R) => void;
42
- nothing: () => void;
43
- }): this;
44
- /**
45
- * Maybe transformer function
46
- *
47
- * Applied to 'just value' returns 'just op(value)'
48
- * Applied to 'nothing' returns self without invoking transformer
49
- *
50
- * @template R2 transformer function's return type
51
- * @param op transformer to be invoked with underlying value
52
- * @returns 'just op(value)' or 'nothing'
53
- */
54
- map<R2>(this: Just<R>, op: (value: R) => R2): Just<R2>;
55
- map<R2>(this: Maybe<R>, op: (value: R) => R2): Maybe<R2>;
56
- /**
57
- * Maybe fallback transformer function
58
- *
59
- * Applied to 'just value' returns self without invoking transformer
60
- * Applied to 'nothing' returns 'just op()'
61
- *
62
- * @param op function to be invoked
63
- * @returns 'just value' or 'just op()'
64
- */
65
- orMap<R2>(this: Just<R>, op: () => R2): Just<R>;
66
- orMap<R2>(this: Maybe<R>, op: () => R2): Just<R | R2>;
67
- /**
68
- * Maybe patter matching transformer function
69
- *
70
- * Applied to 'just value' returns 'just op.just(value)'
71
- * Applied to 'nothing' returns 'just op.nothing()'
72
- *
73
- * @template R2 just transformer function's return type
74
- * @template R3 nothing transformer function's return type
75
- * @param op.just transformer to be invoked with underlying value in case of just
76
- * @param op.nothing transformer to be invoked in case of nothing
77
- * @returns 'just op.just(value)' or 'just op.nothing()'
78
- */
79
- matchMap<R2, R3 = R2>(this: Just<R>, op: {
80
- just: (value: R) => R2;
81
- nothing: () => R3;
82
- }): Just<R2>;
83
- matchMap<R2, R3 = R2>(this: Maybe<R>, op: {
84
- just: (value: R) => R2;
85
- nothing: () => R3;
86
- }): Just<R2 | R3>;
87
- /**
88
- * Maybe composition function
89
- *
90
- * Applied to 'just value' returns 'op(value)'
91
- * Applied to 'nothing' returns self without invoking composition function
92
- *
93
- * @template R2 transformer function result's underlying type
94
- * @param op transformer to be invoked with underlying value
95
- * @returns 'op(value)' or 'nothing'
96
- */
97
- chain<R2>(this: Just<R>, op: (value: R) => Just<R2>): Just<R2>;
98
- chain<R2>(this: Just<R>, op: (value: R) => Nothing<R2>): Nothing<never>;
99
- chain<R2>(this: Just<R>, op: (value: R) => Maybe<R2>): Maybe<R2>;
100
- chain<R2>(this: Maybe<R>, op: (value: R) => Just<R2>): Maybe<R2>;
101
- chain<R2>(this: Maybe<R>, op: (value: R) => Nothing<R2>): Nothing<never>;
102
- chain<R2>(this: Maybe<R>, op: (value: R) => Maybe<R2>): Maybe<R2>;
103
- /**
104
- * Maybe fallback composition function
105
- *
106
- * Applied to 'just value' returns self witjout invoking composition function
107
- * Applied to 'nothing' returns op()
108
- *
109
- * @template R2 transformer function result's underlying type
110
- * @param op transformer to be invoked
111
- * @returns 'just value' or 'op()'
112
- */
113
- orChain<R2>(this: Just<R>, op: () => Just<R2>): Just<R>;
114
- orChain<R2>(this: Just<R>, op: () => Nothing<R2>): Just<R>;
115
- orChain<R2>(this: Just<R>, op: () => Maybe<R2>): Just<R>;
116
- orChain<R2>(this: Maybe<R>, op: () => Just<R2>): Just<R | R2>;
117
- orChain<R2>(this: Maybe<R>, op: () => Nothing<R2>): Maybe<R>;
118
- orChain<R2>(this: Maybe<R>, op: () => Maybe<R2>): Maybe<R | R2>;
119
- /**
120
- * Maybe patter matching composition function
121
- *
122
- * Applied to 'just value' returns 'op.just(value)'
123
- * Applied to 'nothing' returns op.nothing()
124
- *
125
- * @template R2 just transformer function result's underlying type
126
- * @template R3 nothing transformer function result's underlying type
127
- * @param op.just transformer to be invoked with underlying value in case of just
128
- * @param op.nothing transformer to be invoked in case of nothing
129
- * @returns 'op.just(value)' or 'op.nothing()'
130
- */
131
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
132
- just: (value: R) => Just<R2>;
133
- nothing: () => Just<R3>;
134
- }): Just<R2>;
135
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
136
- just: (value: R) => Just<R2>;
137
- nothing: () => Nothing<R3>;
138
- }): Just<R2>;
139
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
140
- just: (value: R) => Nothing<R2>;
141
- nothing: () => Just<R3>;
142
- }): Nothing<never>;
143
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
144
- just: (value: R) => Nothing<R2>;
145
- nothing: () => Nothing<R3>;
146
- }): Nothing<never>;
147
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
148
- just: (value: R) => Just<R2>;
149
- nothing: () => Maybe<R3>;
150
- }): Just<R2>;
151
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
152
- just: (value: R) => Nothing<R2>;
153
- nothing: () => Maybe<R3>;
154
- }): Nothing<never>;
155
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
156
- just: (value: R) => Maybe<R2>;
157
- nothing: () => Just<R3>;
158
- }): Maybe<R2>;
159
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
160
- just: (value: R) => Maybe<R2>;
161
- nothing: () => Nothing<R3>;
162
- }): Maybe<R2>;
163
- matchChain<R2, R3 = R2>(this: Just<R>, op: {
164
- just: (value: R) => Maybe<R2>;
165
- nothing: () => Maybe<R3>;
166
- }): Maybe<R2>;
167
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
168
- just: (value: R) => Just<R2>;
169
- nothing: () => Just<R3>;
170
- }): Just<R2 | R3>;
171
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
172
- just: (value: R) => Just<R2>;
173
- nothing: () => Nothing<R3>;
174
- }): Maybe<R2>;
175
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
176
- just: (value: R) => Nothing<R2>;
177
- nothing: () => Just<R3>;
178
- }): Maybe<R3>;
179
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
180
- just: (value: R) => Nothing<R2>;
181
- nothing: () => Nothing<R3>;
182
- }): Nothing<never>;
183
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
184
- just: (value: R) => Just<R2>;
185
- nothing: () => Maybe<R3>;
186
- }): Maybe<R2 | R3>;
187
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
188
- just: (value: R) => Nothing<R2>;
189
- nothing: () => Maybe<R3>;
190
- }): Maybe<R3>;
191
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
192
- just: (value: R) => Maybe<R2>;
193
- nothing: () => Just<R3>;
194
- }): Maybe<R2 | R3>;
195
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
196
- just: (value: R) => Maybe<R2>;
197
- nothing: () => Nothing<R3>;
198
- }): Maybe<R2>;
199
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
200
- just: (value: R) => Maybe<R2>;
201
- nothing: () => Maybe<R3>;
202
- }): Maybe<R2 | R3>;
203
- /**
204
- * Maybe type guard for 'just'
205
- *
206
- * @returns 'true' in case wrapped value exists (and resolves this type to be 'just')
207
- *
208
- * @example
209
- * ```typescript
210
- * if (maybe.isJust()) {
211
- * console.log(maybe.just);
212
- * }
213
- * ```
214
- */
215
- isJust(): this is Just<R>;
216
- /**
217
- * Maybe type guard for 'nothing'
218
- *
219
- * @returns 'true' in case wrapped value is 'nothing' (and resolves this type to be 'nothing')
220
- *
221
- * @example
222
- * ```typescript
223
- * if (maybe.isNohing()) {
224
- * console.log('nothing');
225
- * }
226
- * ```
227
- */
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>;
237
- }
238
- /**
239
- * Absolutely Nothing
240
- *
241
- * Maybe data type specialiation representing an absence of any value
242
- */
243
- export interface Nothing<R> {
244
- /**
245
- * Maybe peeker function
246
- *
247
- * Applied to 'just value' returns self invoking op(value) in process
248
- * Applied to 'nothing' returns self without invoking callback
249
- *
250
- * @param op function to be invoked with underlying value
251
- * @returns self
252
- */
253
- tap(op: (value: R) => void): this;
254
- /**
255
- * Maybe fallback peeker function
256
- *
257
- * Applied to 'just value' returns self without invoking callback
258
- * Applied to 'nothing' returns self invoking op() in process
259
- *
260
- * @param op function to be invoked
261
- * @returns self
262
- */
263
- orTap(op: () => void): this;
264
- /**
265
- * Maybe patter matching peeker function
266
- *
267
- * Applied to 'just value' returns self invoking op.just(value) in process
268
- * Applied to 'nothing' returns self invoking op.nothing() in process
269
- *
270
- * @param op.just function to be invoked with underlying value in case of just
271
- * @param op.nothing function to be invoked in case of nothing
272
- * @returns self
273
- */
274
- matchTap(op: {
275
- just: (value: R) => void;
276
- nothing: () => void;
277
- }): this;
278
- /**
279
- * Maybe transformer function
280
- *
281
- * Applied to 'just value' returns 'just op(value)'
282
- * Applied to 'nothing' returns self without invoking transformer
283
- *
284
- * @template R2 transformer function's return type
285
- * @param op transformer to be invoked with underlying value
286
- * @returns 'just op(value)' or 'nothing'
287
- */
288
- map<R2>(this: Nothing<R>, op: (value: R) => R2): Nothing<never>;
289
- map<R2>(this: Maybe<R>, op: (value: R) => R2): Maybe<R2>;
290
- /**
291
- * Maybe fallback transformer function
292
- *
293
- * Applied to 'just value' returns self without invoking transformer
294
- * Applied to 'nothing' returns 'just op()'
295
- *
296
- * @param op function to be invoked
297
- * @returns 'just value' or 'just op()'
298
- */
299
- orMap<R2>(this: Nothing<R>, op: () => R2): Just<R2>;
300
- orMap<R2>(this: Maybe<R>, op: () => R2): Just<R | R2>;
301
- /**
302
- * Maybe patter matching transformer function
303
- *
304
- * Applied to 'just value' returns 'just op.just(value)'
305
- * Applied to 'nothing' returns 'just op.nothing()'
306
- *
307
- * @template R2 just transformer function's return type
308
- * @template R3 nothing transformer function's return type
309
- * @param op.just transformer to be invoked with underlying value in case of just
310
- * @param op.nothing transformer to be invoked in case of nothing
311
- * @returns 'just op.just(value)' or 'just op.nothing()'
312
- */
313
- matchMap<R2, R3 = R2>(this: Nothing<R>, op: {
314
- just: (value: R) => R2;
315
- nothing: () => R3;
316
- }): Just<R3>;
317
- matchMap<R2, R3 = R2>(this: Maybe<R>, op: {
318
- just: (value: R) => R2;
319
- nothing: () => R3;
320
- }): Just<R2 | R3>;
321
- /**
322
- * Maybe composition function
323
- *
324
- * Applied to 'just value' returns 'op(value)'
325
- * Applied to 'nothing' returns self without invoking composition function
326
- *
327
- * @template R2 transformer function result's underlying type
328
- * @param op transformer to be invoked with underlying value
329
- * @returns 'op(value)' or 'nothing'
330
- */
331
- chain<R2>(this: Nothing<R>, op: (value: R) => Just<R2>): Nothing<never>;
332
- chain<R2>(this: Nothing<R>, op: (value: R) => Nothing<R2>): Nothing<never>;
333
- chain<R2>(this: Nothing<R>, op: (value: R) => Maybe<R2>): Nothing<never>;
334
- chain<R2>(this: Maybe<R>, op: (value: R) => Just<R2>): Maybe<R2>;
335
- chain<R2>(this: Maybe<R>, op: (value: R) => Nothing<R2>): Nothing<never>;
336
- chain<R2>(this: Maybe<R>, op: (value: R) => Maybe<R2>): Maybe<R2>;
337
- /**
338
- * Maybe fallback composition function
339
- *
340
- * Applied to 'just value' returns self witjout invoking composition function
341
- * Applied to 'nothing' returns op()
342
- *
343
- * @template R2 transformer function result's underlying type
344
- * @param op transformer to be invoked
345
- * @returns 'just value' or 'op()'
346
- */
347
- orChain<R2>(this: Nothing<R>, op: () => Just<R2>): Just<R2>;
348
- orChain<R2>(this: Nothing<R>, op: () => Nothing<R2>): Nothing<never>;
349
- orChain<R2>(this: Nothing<R>, op: () => Maybe<R2>): Maybe<R2>;
350
- orChain<R2>(this: Maybe<R>, op: () => Just<R2>): Just<R | R2>;
351
- orChain<R2>(this: Maybe<R>, op: () => Nothing<R2>): Maybe<R>;
352
- orChain<R2>(this: Maybe<R>, op: () => Maybe<R2>): Maybe<R | R2>;
353
- /**
354
- * Maybe patter matching composition function
355
- *
356
- * Applied to 'just value' returns 'op.just(value)'
357
- * Applied to 'nothing' returns op.nothing()
358
- *
359
- * @template R2 just transformer function result's underlying type
360
- * @template R3 nothing transformer function result's underlying type
361
- * @param op.just transformer to be invoked with underlying value in case of just
362
- * @param op.nothing transformer to be invoked in case of nothing
363
- * @returns 'op.just(value)' or 'op.nothing()'
364
- */
365
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
366
- just: (value: R) => Just<R2>;
367
- nothing: () => Just<R3>;
368
- }): Just<R3>;
369
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
370
- just: (value: R) => Just<R2>;
371
- nothing: () => Nothing<R3>;
372
- }): Nothing<never>;
373
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
374
- just: (value: R) => Nothing<R2>;
375
- nothing: () => Just<R3>;
376
- }): Just<R3>;
377
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
378
- just: (value: R) => Nothing<R2>;
379
- nothing: () => Nothing<R3>;
380
- }): Nothing<never>;
381
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
382
- just: (value: R) => Just<R2>;
383
- nothing: () => Maybe<R3>;
384
- }): Maybe<R3>;
385
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
386
- just: (value: R) => Nothing<R2>;
387
- nothing: () => Maybe<R3>;
388
- }): Maybe<R3>;
389
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
390
- just: (value: R) => Maybe<R2>;
391
- nothing: () => Just<R3>;
392
- }): Just<R3>;
393
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
394
- just: (value: R) => Maybe<R2>;
395
- nothing: () => Nothing<R3>;
396
- }): Nothing<never>;
397
- matchChain<R2, R3 = R2>(this: Nothing<R>, op: {
398
- just: (value: R) => Maybe<R2>;
399
- nothing: () => Maybe<R3>;
400
- }): Maybe<R3>;
401
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
402
- just: (value: R) => Just<R2>;
403
- nothing: () => Just<R3>;
404
- }): Just<R2 | R3>;
405
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
406
- just: (value: R) => Just<R2>;
407
- nothing: () => Nothing<R3>;
408
- }): Maybe<R2>;
409
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
410
- just: (value: R) => Nothing<R2>;
411
- nothing: () => Just<R3>;
412
- }): Maybe<R3>;
413
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
414
- just: (value: R) => Nothing<R2>;
415
- nothing: () => Nothing<R3>;
416
- }): Nothing<never>;
417
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
418
- just: (value: R) => Just<R2>;
419
- nothing: () => Maybe<R3>;
420
- }): Maybe<R2 | R3>;
421
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
422
- just: (value: R) => Nothing<R2>;
423
- nothing: () => Maybe<R3>;
424
- }): Maybe<R3>;
425
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
426
- just: (value: R) => Maybe<R2>;
427
- nothing: () => Just<R3>;
428
- }): Maybe<R2 | R3>;
429
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
430
- just: (value: R) => Maybe<R2>;
431
- nothing: () => Nothing<R3>;
432
- }): Maybe<R2>;
433
- matchChain<R2, R3 = R2>(this: Maybe<R>, op: {
434
- just: (value: R) => Maybe<R2>;
435
- nothing: () => Maybe<R3>;
436
- }): Maybe<R2 | R3>;
437
- /**
438
- * Maybe type guard for 'just'
439
- *
440
- * @returns 'true' in case wrapped value exists (and resolves this type to be 'just')
441
- *
442
- * @example
443
- * ```typescript
444
- * if (maybe.isJust()) {
445
- * console.log(maybe.just);
446
- * }
447
- * ```
448
- */
449
- isJust(): this is Just<R>;
450
- /**
451
- * Maybe type guard for 'nothing'
452
- *
453
- * @returns 'true' in case wrapped value is 'nothing' (and resolves this type to be 'nothing')
454
- *
455
- * @example
456
- * ```typescript
457
- * if (maybe.isNohing()) {
458
- * console.log('nothing');
459
- * }
460
- * ```
461
- */
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>;
471
- }
472
- /**
473
- * Genric Maybe monad interface
474
- *
475
- * As per classic Maybe monad implementation can eithr contain just a value or contain nothing
476
- * Used throughout the library to represent optional return type, specifically return type of cancelled tasks
477
- *
478
- * @template R underlying value
479
- */
480
- export type Maybe<R> = Just<R> | Nothing<R>;
481
- export declare namespace Just {
482
- /**
483
- * Standalone Just value extractor
484
- *
485
- * Userful for passing as a function to collection transformers
486
- *
487
- * @template R underlying value type
488
- * @param just Just instance
489
- * @returns underlying value
490
- */
491
- function just<R>(just: Just<R>): R;
492
- }
493
- export declare namespace Nothing { }
494
- export type MaybeGenerator<T, TT extends Maybe<T>, R> = Generator<TT, R, T>;
495
- export type MaybeGeneratorFunction<A extends unknown[], T, TT extends Maybe<T>, R> = (...args: A) => MaybeGenerator<T, TT, R>;
496
- export declare namespace Maybe {
497
- /**
498
- * Non-empty monad constructor
499
- *
500
- * @template R underlying type
501
- * @param value underlying value
502
- * @returns 'just value'
503
- */
504
- function just<R>(value: R): Just<R>;
505
- /**
506
- * Empty monad constructor
507
- *
508
- * @returns 'nothing'
509
- */
510
- function nothing(): Nothing<never>;
511
- /**
512
- * Maybe constructor from optional value
513
- *
514
- * Resolves to 'nothing' in case of undefined value and 'just value' otherwise
515
- *
516
- * @param value possibly undefined value
517
- * @returns either 'just value' or 'nothing'
518
- */
519
- function fromOptional(value: undefined): Nothing<never>;
520
- function fromOptional<R>(value: Exclude<R, undefined>): Just<R>;
521
- function fromOptional<R>(value: R | undefined): Maybe<R>;
522
- /**
523
- * Maybe constructor from optional or nullable value
524
- *
525
- * Resolves to 'nothing' in case of undefined or null value and 'just value' otherwise
526
- *
527
- * @param value possibly undefined value
528
- * @returns either 'just value' or 'nothing'
529
- */
530
- function fromNullable(value: undefined): Nothing<never>;
531
- function fromNullable(value: null): Nothing<never>;
532
- function fromNullable<R>(value: Exclude<R, null | undefined>): Just<R>;
533
- function fromNullable<R>(value: R | null | undefined): Maybe<R>;
534
- /**
535
- * Standalone type guard for 'just'
536
- *
537
- * Userful for passing as a predicate to collection transformers
538
- *
539
- * @template R underlying value type
540
- * @param maybe Maybe instance
541
- * @returns 'true' in case wrapped value exists (and resolves argument type to be 'just')
542
- */
543
- function isJust<R>(maybe: Maybe<R>): maybe is Just<R>;
544
- /**
545
- * Standalone type guard for 'nothing'
546
- *
547
- * Userful for passing as a predicate to collection transformers
548
- *
549
- * @template R underlying value type
550
- * @param maybe Maybe instance
551
- * @returns 'true' in case wrapped value is 'nothing' (and resolves argument type to be 'nothing')
552
- */
553
- function isNothing<R>(maybe: Maybe<R>): maybe is Nothing<never>;
554
- /**
555
- * Standalone list predicate
556
- *
557
- * @param maybes a list of Maybe
558
- * @returns true in case every list element is Just
559
- */
560
- function everyJust<R>(maybes: Maybe<R>[]): maybes is Just<R>[];
561
- /**
562
- * Standalone list predicate
563
- *
564
- * @param maybes a list of Maybe
565
- * @returns true in case al east one list element is Just
566
- */
567
- function someJust<R>(maybes: Maybe<R>[]): boolean;
568
- /**
569
- * Standalone list predicate
570
- *
571
- * @param maybes a list of Maybe
572
- * @returns true in case every list element is Nothing
573
- */
574
- function everyNothing<R>(maybes: Maybe<R>[]): maybes is Nothing<never>[];
575
- /**
576
- * Standalone list predicate
577
- *
578
- * @param maybes a list of Maybe
579
- * @returns true in case at least one list element is Nothing
580
- */
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>;
595
- }
@@ -1,2 +0,0 @@
1
- let t,e,r;var n;(t||(t={})).just=function(t){return t.just},(n=r||(r={})).just=function(t){return new i(t)},n.nothing=function(){return u},n.fromOptional=function(t){return void 0!==t?r.just(t):r.nothing()},n.fromNullable=function(t){return r.fromOptional(t).chain(t=>null!==t?r.just(t):r.nothing())},n.isJust=function(t){return t.isJust()},n.isNothing=function(t){return t.isNothing()},n.everyJust=function(t){return t.every(r.isJust)},n.someJust=function(t){return t.some(r.isJust)},n.everyNothing=function(t){return t.every(r.isNothing)},n.someNothing=function(t){return t.some(r.isNothing)},n.generate=function(t){const e=t(),n=t=>t.done?r.just(t.value):t.value.matchChain({just:t=>n(e.next(t)),nothing:r.nothing});return r.just(void 0).chain(()=>n(e.next()))};class i{constructor(t){this.just=t}tap(t){return t(this.just),this}orTap(){return this}map(t){return r.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(){return function*(t){return yield t}(this)}}const u=new class{tap(){return this}orTap(t){return t(),this}map(){return this}orMap(t){return r.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(){return function*(t){return yield t}(this)}};let o,c,a;var s;(o||(o={})).right=function(t){return t.right},(c||(c={})).left=function(t){return t.left},(s=a||(a={})).right=function(t){return new h(t)},s.left=function(t){return new l(t)},s.fromOptional=function(t,e){return void 0!==t?a.right(t):a.left(e)},s.fromNullable=function(t,e){return a.fromOptional(t,e).chain(r=>null!==r?a.right(t):a.left(e))},s.isRight=function(t){return t.isRight()},s.isLeft=function(t){return t.isLeft()},s.everyRight=function(t){return t.every(a.isRight)},s.someRight=function(t){return t.some(a.isRight)},s.everyLeft=function(t){return t.every(a.isLeft)},s.someLeft=function(t){return t.some(a.isLeft)},s.generate=function(t){const e=t(),r=t=>t.done?a.right(t.value):t.value.matchChain({right:t=>r(e.next(t)),left:a.left});return a.right(void 0).chain(()=>r(e.next()))};class h{constructor(t){this.right=t}tap(t){return t(this.right),this}orTap(){return this}map(t){return a.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(){return function*(t){return yield t}(this)}}class l{constructor(t){this.left=t}tap(){return this}orTap(t){return t(this.left),this}map(){return this}orMap(t){return a.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(){return function*(t){return yield t}(this)}}let f;!function(e){function n(t){const e=t(),r=t=>t.done?f.resolved(t.value):t.value.matchChain({resolved:t=>r(e.next(t)),rejected:t=>r(e.throw(t)),canceled:f.canceled});return f.resolved(void 0).chain(()=>r(e.next()))}function i(t,e){let n;const[i,u]=m();return f.create(new Promise(e=>{u(e),n=t(t=>i(r.just(a.right(t))),t=>i(r.just(a.left(t))),()=>i(r.nothing()))}),t=>{i(t.map(a.left)),e(n)})}e.create=function(t,e){return new M(t,e)},e.resolved=function(t){return f.create(Promise.resolve(r.just(a.right(t))),()=>{})},e.rejected=function(t){return f.create(Promise.resolve(r.just(a.left(t))),()=>{})},e.canceled=function(){return f.create(Promise.resolve(r.nothing()),()=>{})},e.fromPromise=function(t){const[e,n]=m();return f.create(new Promise(i=>{n(i),t.then(a.right,a.left).then(r.just).then(e)}),t=>e(t.map(a.left)))},e.fromFunction=function(t,e){const[n,i]=m(),u=t=>n(t.map(a.left));return e.cancel=u,f.create(new Promise(e=>{i(e);try{n(r.just(a.right(t())))}catch(t){n(r.just(a.left(t)))}}),u)},e.promiseGenerator=function(t){return f.fromPromise(t).generator()},e.timeoutGenerator=function(t){return f.timeout(t).generator()},e.lift=function(t){return(...e)=>f.fromPromise(t(...e))},e.generate=n,e.generateFunction=function(t){return(...e)=>n(function*(){return yield*t(...e)})},e.timeout=function(t){return i(e=>setTimeout(()=>e(),t),clearTimeout)},e.fromCallback=i,e.sequence=function(t){return Array.from(t).reduce((t,e)=>t.chain(t=>e().map(e=>t.concat(e))),f.resolved([]))},e.all=function(e){const[n,i]=m(),u=Array.from(e),o=t=>u.forEach(e=>e._cancel(t)),c=u.map(r.nothing),s=t=>{n(t.map(a.left)),o(t)};return f.create(new Promise(e=>{if(i(e),u.length<1)return n(r.just(a.right([])));u.map((e,i)=>e.matchTap({resolved:e=>((e,i)=>{c[i]=r.just(e),r.everyJust(c)&&n(r.just(a.right(c.map(t.just))))})(e,i),rejected:t=>s(r.just(t)),canceled:()=>s(r.nothing())}))}),o)},e.any=function(e){const[n,i]=m(),u=Array.from(e),o=t=>u.forEach(e=>e._cancel(t)),c=u.map(r.nothing),s=t=>{n(t.map(a.right)),o(r.nothing())};return f.create(new Promise(e=>{if(i(e),u.length<1)return n(r.nothing());u.map((e,i)=>e.matchTap({resolved:t=>s(r.just(t)),rejected:e=>((e,i)=>{c[i]=r.just(e),r.everyJust(c)&&n(r.just(a.left(c.map(t.just))))})(e,i),canceled:()=>s(r.nothing())}))}),o)},e.limit=function(t,e){return f.any([t,e.chain(f.canceled)]).chainRejected(t=>f.rejected(t[0]))},e.repeat=function(t){const e=()=>t().chainRejected(e);return e()}}(f||(f={}));const m=()=>{const t=()=>{};let e=t;return[r=>{const n=e;e=t,n(r)},t=>{e=t}]};function g(t,e){const n={cancel:t._cancel};return f.create(t._invoke.then(async t=>{try{const{_invoke:i,_cancel:u}=f.fromFunction(()=>e(t),n);n.cancel=u;const o=await i;if(o.isNothing())return r.nothing();if(o.just.isLeft())return r.just(a.left(o.just.left));const{_invoke:c,_cancel:s}=o.just.right;return n.cancel=s,c}catch(t){return r.just(a.left(t))}}),t=>n.cancel(t))}function p(t,e){return g(t,t=>t.map(e).orMap(f.canceled).just)}function j(t,e){return g(t,t=>e(t).matchMap({just:t=>t.matchMap({right:f.resolved,left:f.rejected}).right,nothing:f.canceled}).just)}function d(t,e){return j(t,t=>t.map(e))}function v(t,e){return j(t,t=>(e(t),t))}function y(t,e){return v(t,t=>t.tap(e))}class M{constructor(t,e){this._invoke=t,this._cancel=e}tapCanceled(t){return v(this,e=>e.orTap(t))}tapRejected(t){return y(this,e=>e.orTap(t))}tap(t){return y(this,e=>e.tap(t))}mapCanceled(t){return j(this,e=>e.orMap(()=>a.right(t())))}mapRejected(t){return d(this,e=>e.orMap(t))}map(t){return d(this,e=>e.map(t))}chainCanceled(t){const e=t=>t.map(f.resolved).orMap(f.rejected).right;return g(this,r=>r.map(e).orMap(t).just)}chainRejected(t){return p(this,e=>e.map(f.resolved).orMap(t).right)}chain(t){return p(this,e=>e.map(t).orMap(f.rejected).right)}resolve(){return this._invoke}cancel(){return this._cancel(r.nothing())}reject(t){return this._cancel(r.just(t))}generator(){return function*(t){return yield t}(this)}matchTap(t){return v(this,e=>e.matchTap({just:e=>e.matchTap({right:t.resolved,left:t.rejected}),nothing:t.canceled}))}matchMap(t){return j(this,e=>e.matchMap({just:e=>e.matchMap({right:t.resolved,left:t.rejected}),nothing:()=>a.right(t.canceled())}))}matchChain(t){return g(this,e=>e.matchMap({just:e=>e.matchMap({right:t.resolved,left:t.rejected}).right,nothing:t.canceled}).just)}}export{a as Either,t as Just,c as Left,r as Maybe,e as Nothing,o as Right,f as Task};
2
- //# sourceMappingURL=t-tasks.modern.mjs.map