t-tasks 0.9.6 → 1.0.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/maybe.d.ts +3 -3
- package/dist/t-tasks.esm.js +1 -2058
- package/dist/t-tasks.esm.js.map +1 -1
- package/dist/t-tasks.js +2 -0
- package/dist/t-tasks.js.map +1 -0
- package/dist/t-tasks.modern.js +2 -0
- package/dist/t-tasks.modern.js.map +1 -0
- package/dist/t-tasks.umd.js +2 -0
- package/dist/t-tasks.umd.js.map +1 -0
- package/package.json +23 -27
- package/src/maybe.ts +3 -3
- package/src/task.ts +12 -4
- package/dist/index.js +0 -8
- package/dist/t-tasks.cjs.development.js +0 -2049
- package/dist/t-tasks.cjs.development.js.map +0 -1
- package/dist/t-tasks.cjs.production.min.js +0 -2
- package/dist/t-tasks.cjs.production.min.js.map +0 -1
package/dist/t-tasks.esm.js
CHANGED
|
@@ -1,2059 +1,2 @@
|
|
|
1
|
-
var Just;
|
|
2
|
-
|
|
3
|
-
(function (Just) {
|
|
4
|
-
/**
|
|
5
|
-
* Standalone Just value extractor
|
|
6
|
-
*
|
|
7
|
-
* Userful for passing as a function to collection transformers
|
|
8
|
-
*
|
|
9
|
-
* @template R underlying value type
|
|
10
|
-
* @param just Just instance
|
|
11
|
-
* @returns underlying value
|
|
12
|
-
*/
|
|
13
|
-
function just(just) {
|
|
14
|
-
return just.just;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Just.just = just;
|
|
18
|
-
})(Just || (Just = {}));
|
|
19
|
-
|
|
20
|
-
var Maybe;
|
|
21
|
-
|
|
22
|
-
(function (Maybe) {
|
|
23
|
-
/**
|
|
24
|
-
* Non-empty monad constructor
|
|
25
|
-
*
|
|
26
|
-
* @template R underlying type
|
|
27
|
-
* @param value underlying value
|
|
28
|
-
* @returns 'just value'
|
|
29
|
-
*/
|
|
30
|
-
function just(value) {
|
|
31
|
-
return new JustClass(value);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Maybe.just = just;
|
|
35
|
-
/**
|
|
36
|
-
* Empty monad constructor
|
|
37
|
-
*
|
|
38
|
-
* @returns 'nothing'
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
function nothing() {
|
|
42
|
-
return staticNothing;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
Maybe.nothing = nothing;
|
|
46
|
-
|
|
47
|
-
function fromOptional(value) {
|
|
48
|
-
return typeof value !== 'undefined' ? Maybe.just(value) : Maybe.nothing();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
Maybe.fromOptional = fromOptional;
|
|
52
|
-
|
|
53
|
-
function fromNullable(value) {
|
|
54
|
-
return Maybe.fromOptional(value).chain(function (v) {
|
|
55
|
-
return v !== null ? Maybe.just(v) : Maybe.nothing();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
Maybe.fromNullable = fromNullable;
|
|
60
|
-
/**
|
|
61
|
-
* Standalone type guard for 'just'
|
|
62
|
-
*
|
|
63
|
-
* Userful for passing as a predicate to collection transformers
|
|
64
|
-
*
|
|
65
|
-
* @template R underlying value type
|
|
66
|
-
* @param maybe Maybe instance
|
|
67
|
-
* @returns 'true' in case wrapped value exists (and resolves argument type to be 'just')
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
function isJust(maybe) {
|
|
71
|
-
return maybe.isJust();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
Maybe.isJust = isJust;
|
|
75
|
-
/**
|
|
76
|
-
* Standalone type guard for 'nothing'
|
|
77
|
-
*
|
|
78
|
-
* Userful for passing as a predicate to collection transformers
|
|
79
|
-
*
|
|
80
|
-
* @template R underlying value type
|
|
81
|
-
* @param maybe Maybe instance
|
|
82
|
-
* @returns 'true' in case wrapped value is 'nothing' (and resolves argument type to be 'nothing')
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
function isNothing(maybe) {
|
|
86
|
-
return maybe.isNothing();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
Maybe.isNothing = isNothing;
|
|
90
|
-
/**
|
|
91
|
-
* Standalone list predicate
|
|
92
|
-
*
|
|
93
|
-
* @param maybes a list of Maybe
|
|
94
|
-
* @returns true in case every list element is Just
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
function everyJust(maybes) {
|
|
98
|
-
return maybes.every(Maybe.isJust);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
Maybe.everyJust = everyJust;
|
|
102
|
-
/**
|
|
103
|
-
* Standalone list predicate
|
|
104
|
-
*
|
|
105
|
-
* @param maybes a list of Maybe
|
|
106
|
-
* @returns true in case al east one list element is Just
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
function someJust(maybes) {
|
|
110
|
-
return maybes.some(Maybe.isJust);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
Maybe.someJust = someJust;
|
|
114
|
-
/**
|
|
115
|
-
* Standalone list predicate
|
|
116
|
-
*
|
|
117
|
-
* @param maybes a list of Maybe
|
|
118
|
-
* @returns true in case every list element is Nothing
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
function everyNothing(maybes) {
|
|
122
|
-
return maybes.every(Maybe.isNothing);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
Maybe.everyNothing = everyNothing;
|
|
126
|
-
/**
|
|
127
|
-
* Standalone list predicate
|
|
128
|
-
*
|
|
129
|
-
* @param maybes a list of Maybe
|
|
130
|
-
* @returns true in case at least one list element is Nothing
|
|
131
|
-
*/
|
|
132
|
-
|
|
133
|
-
function someNothing(maybes) {
|
|
134
|
-
return maybes.some(Maybe.isNothing);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
Maybe.someNothing = someNothing;
|
|
138
|
-
})(Maybe || (Maybe = {})); /// --------------------------------------------------------------------------------------
|
|
139
|
-
/// Private section
|
|
140
|
-
/// --------------------------------------------------------------------------------------
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var JustClass = /*#__PURE__*/function () {
|
|
144
|
-
function JustClass(just) {
|
|
145
|
-
this.just = just;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
var _proto = JustClass.prototype;
|
|
149
|
-
|
|
150
|
-
_proto.tap = function tap(op) {
|
|
151
|
-
op(this.just);
|
|
152
|
-
return this;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
_proto.orTap = function orTap() {
|
|
156
|
-
return this;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
_proto.map = function map(op) {
|
|
160
|
-
return Maybe.just(op(this.just));
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
_proto.orMap = function orMap() {
|
|
164
|
-
return this;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
_proto.chain = function chain(op) {
|
|
168
|
-
return op(this.just);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
_proto.orChain = function orChain() {
|
|
172
|
-
return this;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
_proto.isJust = function isJust() {
|
|
176
|
-
return true;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
_proto.isNothing = function isNothing() {
|
|
180
|
-
return false;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
_proto.matchTap = function matchTap(op) {
|
|
184
|
-
return this.tap(op.just);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
_proto.matchMap = function matchMap(op) {
|
|
188
|
-
return this.map(op.just);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
_proto.matchChain = function matchChain(op) {
|
|
192
|
-
return this.chain(op.just);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
return JustClass;
|
|
196
|
-
}();
|
|
197
|
-
|
|
198
|
-
var NothingClass = /*#__PURE__*/function () {
|
|
199
|
-
function NothingClass() {}
|
|
200
|
-
|
|
201
|
-
var _proto2 = NothingClass.prototype;
|
|
202
|
-
|
|
203
|
-
_proto2.tap = function tap() {
|
|
204
|
-
return this;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
_proto2.orTap = function orTap(op) {
|
|
208
|
-
op();
|
|
209
|
-
return this;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
_proto2.map = function map() {
|
|
213
|
-
return this;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
_proto2.orMap = function orMap(op) {
|
|
217
|
-
return Maybe.just(op());
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
_proto2.chain = function chain() {
|
|
221
|
-
return this;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
_proto2.orChain = function orChain(op) {
|
|
225
|
-
return op();
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
_proto2.isJust = function isJust() {
|
|
229
|
-
return false;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
_proto2.isNothing = function isNothing() {
|
|
233
|
-
return true;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
_proto2.matchTap = function matchTap(op) {
|
|
237
|
-
return this.orTap(op.nothing);
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
_proto2.matchMap = function matchMap(op) {
|
|
241
|
-
return this.orMap(op.nothing);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
_proto2.matchChain = function matchChain(op) {
|
|
245
|
-
return this.orChain(op.nothing);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
return NothingClass;
|
|
249
|
-
}();
|
|
250
|
-
|
|
251
|
-
var staticNothing = /*#__PURE__*/new NothingClass();
|
|
252
|
-
|
|
253
|
-
var Right;
|
|
254
|
-
|
|
255
|
-
(function (Right) {
|
|
256
|
-
/**
|
|
257
|
-
* Standalone Right value extractor
|
|
258
|
-
*
|
|
259
|
-
* Userful for passing as a function to collection transformers
|
|
260
|
-
*
|
|
261
|
-
* @template R underlying value type
|
|
262
|
-
* @template L underlying error type
|
|
263
|
-
* @param right Right instance
|
|
264
|
-
* @returns underlying value
|
|
265
|
-
*/
|
|
266
|
-
function right(right) {
|
|
267
|
-
return right.right;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
Right.right = right;
|
|
271
|
-
})(Right || (Right = {}));
|
|
272
|
-
|
|
273
|
-
var Left;
|
|
274
|
-
|
|
275
|
-
(function (Left) {
|
|
276
|
-
/**
|
|
277
|
-
* Standalone Left error extractor
|
|
278
|
-
*
|
|
279
|
-
* Userful for passing as a function to collection transformers
|
|
280
|
-
*
|
|
281
|
-
* @template R underlying value type
|
|
282
|
-
* @template L underlying error type
|
|
283
|
-
* @param left Left instance
|
|
284
|
-
* @returns underlying error
|
|
285
|
-
*/
|
|
286
|
-
function left(left) {
|
|
287
|
-
return left.left;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
Left.left = left;
|
|
291
|
-
})(Left || (Left = {}));
|
|
292
|
-
|
|
293
|
-
var Either;
|
|
294
|
-
|
|
295
|
-
(function (Either) {
|
|
296
|
-
/**
|
|
297
|
-
* Right monad constructor
|
|
298
|
-
*
|
|
299
|
-
* @template R underlying value type
|
|
300
|
-
* @param value underlying value
|
|
301
|
-
* @returns 'right value'
|
|
302
|
-
*/
|
|
303
|
-
function right(value) {
|
|
304
|
-
return new RightClass(value);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
Either.right = right;
|
|
308
|
-
/**
|
|
309
|
-
* Left monad constructor
|
|
310
|
-
*
|
|
311
|
-
* @template L underlying error type
|
|
312
|
-
* @param error underlying error
|
|
313
|
-
* @returns 'left error'
|
|
314
|
-
*/
|
|
315
|
-
|
|
316
|
-
function left(error) {
|
|
317
|
-
return new LeftClass(error);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
Either.left = left;
|
|
321
|
-
|
|
322
|
-
function fromOptional(value, error) {
|
|
323
|
-
return typeof value !== 'undefined' ? Either.right(value) : Either.left(error);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
Either.fromOptional = fromOptional;
|
|
327
|
-
|
|
328
|
-
function fromNullable(value, error) {
|
|
329
|
-
return Either.fromOptional(value, error).chain(function (v) {
|
|
330
|
-
return v !== null ? Either.right(value) : Either.left(error);
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
Either.fromNullable = fromNullable;
|
|
335
|
-
/**
|
|
336
|
-
* Standalone type guard for 'right'
|
|
337
|
-
*
|
|
338
|
-
* Userful for passing as a predicate to collection transformers
|
|
339
|
-
*
|
|
340
|
-
* @template R underlying value type
|
|
341
|
-
* @param either Either instance
|
|
342
|
-
* @returns 'true' in case argument is 'right value' (and resolves type to be 'right')
|
|
343
|
-
*/
|
|
344
|
-
|
|
345
|
-
function isRight(either) {
|
|
346
|
-
return either.isRight();
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
Either.isRight = isRight;
|
|
350
|
-
/**
|
|
351
|
-
* Standalone type guard for 'left'
|
|
352
|
-
*
|
|
353
|
-
* Userful for passing as a predicate to collection transformers
|
|
354
|
-
*
|
|
355
|
-
* @template R underlying value type
|
|
356
|
-
* @param either Either instance
|
|
357
|
-
* @returns 'true' in case argument is 'left error' (and resolves type to be 'left')
|
|
358
|
-
*/
|
|
359
|
-
|
|
360
|
-
function isLeft(either) {
|
|
361
|
-
return either.isLeft();
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
Either.isLeft = isLeft;
|
|
365
|
-
/**
|
|
366
|
-
* Standalone list predicate
|
|
367
|
-
*
|
|
368
|
-
* @param eithers a list of Either
|
|
369
|
-
* @returns true in case every list element is Right
|
|
370
|
-
*/
|
|
371
|
-
|
|
372
|
-
function everyRight(eithers) {
|
|
373
|
-
return eithers.every(Either.isRight);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
Either.everyRight = everyRight;
|
|
377
|
-
/**
|
|
378
|
-
* Standalone list predicate
|
|
379
|
-
*
|
|
380
|
-
* @param eithers a list of Either
|
|
381
|
-
* @returns true in case at least one list element is Right
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
function someRight(eithers) {
|
|
385
|
-
return eithers.some(Either.isRight);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
Either.someRight = someRight;
|
|
389
|
-
/**
|
|
390
|
-
* Standalone list predicate
|
|
391
|
-
*
|
|
392
|
-
* @param eithers a list of Either
|
|
393
|
-
* @returns true in case every list element is Left
|
|
394
|
-
*/
|
|
395
|
-
|
|
396
|
-
function everyLeft(eithers) {
|
|
397
|
-
return eithers.every(Either.isLeft);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
Either.everyLeft = everyLeft;
|
|
401
|
-
/**
|
|
402
|
-
* Standalone list predicate
|
|
403
|
-
*
|
|
404
|
-
* @param eithers a list of Either
|
|
405
|
-
* @returns true in case at least one list element is Left
|
|
406
|
-
*/
|
|
407
|
-
|
|
408
|
-
function someLeft(eithers) {
|
|
409
|
-
return eithers.some(Either.isLeft);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
Either.someLeft = someLeft;
|
|
413
|
-
})(Either || (Either = {})); /// --------------------------------------------------------------------------------------
|
|
414
|
-
/// Private section
|
|
415
|
-
/// --------------------------------------------------------------------------------------
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
var RightClass = /*#__PURE__*/function () {
|
|
419
|
-
function RightClass(right) {
|
|
420
|
-
this.right = right;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
var _proto = RightClass.prototype;
|
|
424
|
-
|
|
425
|
-
_proto.tap = function tap(op) {
|
|
426
|
-
op(this.right);
|
|
427
|
-
return this;
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
_proto.orTap = function orTap() {
|
|
431
|
-
return this;
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
_proto.map = function map(op) {
|
|
435
|
-
return Either.right(op(this.right));
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
_proto.orMap = function orMap() {
|
|
439
|
-
return this;
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
_proto.chain = function chain(op) {
|
|
443
|
-
return op(this.right);
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
_proto.orChain = function orChain() {
|
|
447
|
-
return this;
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
_proto.isRight = function isRight() {
|
|
451
|
-
return true;
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
_proto.isLeft = function isLeft() {
|
|
455
|
-
return false;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
_proto.matchTap = function matchTap(op) {
|
|
459
|
-
return this.tap(op.right);
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
_proto.matchMap = function matchMap(op) {
|
|
463
|
-
return this.map(op.right);
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
_proto.matchChain = function matchChain(op) {
|
|
467
|
-
return this.chain(op.right);
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
return RightClass;
|
|
471
|
-
}();
|
|
472
|
-
|
|
473
|
-
var LeftClass = /*#__PURE__*/function () {
|
|
474
|
-
function LeftClass(left) {
|
|
475
|
-
this.left = left;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
var _proto2 = LeftClass.prototype;
|
|
479
|
-
|
|
480
|
-
_proto2.tap = function tap() {
|
|
481
|
-
return this;
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
_proto2.orTap = function orTap(op) {
|
|
485
|
-
op(this.left);
|
|
486
|
-
return this;
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
_proto2.map = function map() {
|
|
490
|
-
return this;
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
_proto2.orMap = function orMap(op) {
|
|
494
|
-
return Either.right(op(this.left));
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
_proto2.chain = function chain() {
|
|
498
|
-
return this;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
_proto2.orChain = function orChain(op) {
|
|
502
|
-
return op(this.left);
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
_proto2.isRight = function isRight() {
|
|
506
|
-
return false;
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
_proto2.isLeft = function isLeft() {
|
|
510
|
-
return true;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
_proto2.matchTap = function matchTap(op) {
|
|
514
|
-
return this.orTap(op.left);
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
_proto2.matchMap = function matchMap(op) {
|
|
518
|
-
return this.orMap(op.left);
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
_proto2.matchChain = function matchChain(op) {
|
|
522
|
-
return this.orChain(op.left);
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
return LeftClass;
|
|
526
|
-
}();
|
|
527
|
-
|
|
528
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
529
|
-
try {
|
|
530
|
-
var info = gen[key](arg);
|
|
531
|
-
var value = info.value;
|
|
532
|
-
} catch (error) {
|
|
533
|
-
reject(error);
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
if (info.done) {
|
|
538
|
-
resolve(value);
|
|
539
|
-
} else {
|
|
540
|
-
Promise.resolve(value).then(_next, _throw);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
function _asyncToGenerator(fn) {
|
|
545
|
-
return function () {
|
|
546
|
-
var self = this,
|
|
547
|
-
args = arguments;
|
|
548
|
-
return new Promise(function (resolve, reject) {
|
|
549
|
-
var gen = fn.apply(self, args);
|
|
550
|
-
|
|
551
|
-
function _next(value) {
|
|
552
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
function _throw(err) {
|
|
556
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
_next(undefined);
|
|
560
|
-
});
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function createCommonjsModule(fn, module) {
|
|
565
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
var runtime_1 = createCommonjsModule(function (module) {
|
|
569
|
-
/**
|
|
570
|
-
* Copyright (c) 2014-present, Facebook, Inc.
|
|
571
|
-
*
|
|
572
|
-
* This source code is licensed under the MIT license found in the
|
|
573
|
-
* LICENSE file in the root directory of this source tree.
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
var runtime = (function (exports) {
|
|
577
|
-
|
|
578
|
-
var Op = Object.prototype;
|
|
579
|
-
var hasOwn = Op.hasOwnProperty;
|
|
580
|
-
var undefined$1; // More compressible than void 0.
|
|
581
|
-
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
582
|
-
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
583
|
-
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
584
|
-
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
585
|
-
|
|
586
|
-
function define(obj, key, value) {
|
|
587
|
-
Object.defineProperty(obj, key, {
|
|
588
|
-
value: value,
|
|
589
|
-
enumerable: true,
|
|
590
|
-
configurable: true,
|
|
591
|
-
writable: true
|
|
592
|
-
});
|
|
593
|
-
return obj[key];
|
|
594
|
-
}
|
|
595
|
-
try {
|
|
596
|
-
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
597
|
-
define({}, "");
|
|
598
|
-
} catch (err) {
|
|
599
|
-
define = function(obj, key, value) {
|
|
600
|
-
return obj[key] = value;
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
605
|
-
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
606
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
607
|
-
var generator = Object.create(protoGenerator.prototype);
|
|
608
|
-
var context = new Context(tryLocsList || []);
|
|
609
|
-
|
|
610
|
-
// The ._invoke method unifies the implementations of the .next,
|
|
611
|
-
// .throw, and .return methods.
|
|
612
|
-
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
613
|
-
|
|
614
|
-
return generator;
|
|
615
|
-
}
|
|
616
|
-
exports.wrap = wrap;
|
|
617
|
-
|
|
618
|
-
// Try/catch helper to minimize deoptimizations. Returns a completion
|
|
619
|
-
// record like context.tryEntries[i].completion. This interface could
|
|
620
|
-
// have been (and was previously) designed to take a closure to be
|
|
621
|
-
// invoked without arguments, but in all the cases we care about we
|
|
622
|
-
// already have an existing method we want to call, so there's no need
|
|
623
|
-
// to create a new function object. We can even get away with assuming
|
|
624
|
-
// the method takes exactly one argument, since that happens to be true
|
|
625
|
-
// in every case, so we don't have to touch the arguments object. The
|
|
626
|
-
// only additional allocation required is the completion record, which
|
|
627
|
-
// has a stable shape and so hopefully should be cheap to allocate.
|
|
628
|
-
function tryCatch(fn, obj, arg) {
|
|
629
|
-
try {
|
|
630
|
-
return { type: "normal", arg: fn.call(obj, arg) };
|
|
631
|
-
} catch (err) {
|
|
632
|
-
return { type: "throw", arg: err };
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
var GenStateSuspendedStart = "suspendedStart";
|
|
637
|
-
var GenStateSuspendedYield = "suspendedYield";
|
|
638
|
-
var GenStateExecuting = "executing";
|
|
639
|
-
var GenStateCompleted = "completed";
|
|
640
|
-
|
|
641
|
-
// Returning this object from the innerFn has the same effect as
|
|
642
|
-
// breaking out of the dispatch switch statement.
|
|
643
|
-
var ContinueSentinel = {};
|
|
644
|
-
|
|
645
|
-
// Dummy constructor functions that we use as the .constructor and
|
|
646
|
-
// .constructor.prototype properties for functions that return Generator
|
|
647
|
-
// objects. For full spec compliance, you may wish to configure your
|
|
648
|
-
// minifier not to mangle the names of these two functions.
|
|
649
|
-
function Generator() {}
|
|
650
|
-
function GeneratorFunction() {}
|
|
651
|
-
function GeneratorFunctionPrototype() {}
|
|
652
|
-
|
|
653
|
-
// This is a polyfill for %IteratorPrototype% for environments that
|
|
654
|
-
// don't natively support it.
|
|
655
|
-
var IteratorPrototype = {};
|
|
656
|
-
IteratorPrototype[iteratorSymbol] = function () {
|
|
657
|
-
return this;
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
var getProto = Object.getPrototypeOf;
|
|
661
|
-
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
662
|
-
if (NativeIteratorPrototype &&
|
|
663
|
-
NativeIteratorPrototype !== Op &&
|
|
664
|
-
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
665
|
-
// This environment has a native %IteratorPrototype%; use it instead
|
|
666
|
-
// of the polyfill.
|
|
667
|
-
IteratorPrototype = NativeIteratorPrototype;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
var Gp = GeneratorFunctionPrototype.prototype =
|
|
671
|
-
Generator.prototype = Object.create(IteratorPrototype);
|
|
672
|
-
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
|
|
673
|
-
GeneratorFunctionPrototype.constructor = GeneratorFunction;
|
|
674
|
-
GeneratorFunction.displayName = define(
|
|
675
|
-
GeneratorFunctionPrototype,
|
|
676
|
-
toStringTagSymbol,
|
|
677
|
-
"GeneratorFunction"
|
|
678
|
-
);
|
|
679
|
-
|
|
680
|
-
// Helper for defining the .next, .throw, and .return methods of the
|
|
681
|
-
// Iterator interface in terms of a single ._invoke method.
|
|
682
|
-
function defineIteratorMethods(prototype) {
|
|
683
|
-
["next", "throw", "return"].forEach(function(method) {
|
|
684
|
-
define(prototype, method, function(arg) {
|
|
685
|
-
return this._invoke(method, arg);
|
|
686
|
-
});
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
exports.isGeneratorFunction = function(genFun) {
|
|
691
|
-
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
692
|
-
return ctor
|
|
693
|
-
? ctor === GeneratorFunction ||
|
|
694
|
-
// For the native GeneratorFunction constructor, the best we can
|
|
695
|
-
// do is to check its .name property.
|
|
696
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
697
|
-
: false;
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
exports.mark = function(genFun) {
|
|
701
|
-
if (Object.setPrototypeOf) {
|
|
702
|
-
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
703
|
-
} else {
|
|
704
|
-
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
705
|
-
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
706
|
-
}
|
|
707
|
-
genFun.prototype = Object.create(Gp);
|
|
708
|
-
return genFun;
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
// Within the body of any async function, `await x` is transformed to
|
|
712
|
-
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
713
|
-
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
714
|
-
// meant to be awaited.
|
|
715
|
-
exports.awrap = function(arg) {
|
|
716
|
-
return { __await: arg };
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
720
|
-
function invoke(method, arg, resolve, reject) {
|
|
721
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
722
|
-
if (record.type === "throw") {
|
|
723
|
-
reject(record.arg);
|
|
724
|
-
} else {
|
|
725
|
-
var result = record.arg;
|
|
726
|
-
var value = result.value;
|
|
727
|
-
if (value &&
|
|
728
|
-
typeof value === "object" &&
|
|
729
|
-
hasOwn.call(value, "__await")) {
|
|
730
|
-
return PromiseImpl.resolve(value.__await).then(function(value) {
|
|
731
|
-
invoke("next", value, resolve, reject);
|
|
732
|
-
}, function(err) {
|
|
733
|
-
invoke("throw", err, resolve, reject);
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
738
|
-
// When a yielded Promise is resolved, its final value becomes
|
|
739
|
-
// the .value of the Promise<{value,done}> result for the
|
|
740
|
-
// current iteration.
|
|
741
|
-
result.value = unwrapped;
|
|
742
|
-
resolve(result);
|
|
743
|
-
}, function(error) {
|
|
744
|
-
// If a rejected Promise was yielded, throw the rejection back
|
|
745
|
-
// into the async generator function so it can be handled there.
|
|
746
|
-
return invoke("throw", error, resolve, reject);
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
var previousPromise;
|
|
752
|
-
|
|
753
|
-
function enqueue(method, arg) {
|
|
754
|
-
function callInvokeWithMethodAndArg() {
|
|
755
|
-
return new PromiseImpl(function(resolve, reject) {
|
|
756
|
-
invoke(method, arg, resolve, reject);
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
return previousPromise =
|
|
761
|
-
// If enqueue has been called before, then we want to wait until
|
|
762
|
-
// all previous Promises have been resolved before calling invoke,
|
|
763
|
-
// so that results are always delivered in the correct order. If
|
|
764
|
-
// enqueue has not been called before, then it is important to
|
|
765
|
-
// call invoke immediately, without waiting on a callback to fire,
|
|
766
|
-
// so that the async generator function has the opportunity to do
|
|
767
|
-
// any necessary setup in a predictable way. This predictability
|
|
768
|
-
// is why the Promise constructor synchronously invokes its
|
|
769
|
-
// executor callback, and why async functions synchronously
|
|
770
|
-
// execute code before the first await. Since we implement simple
|
|
771
|
-
// async functions in terms of async generators, it is especially
|
|
772
|
-
// important to get this right, even though it requires care.
|
|
773
|
-
previousPromise ? previousPromise.then(
|
|
774
|
-
callInvokeWithMethodAndArg,
|
|
775
|
-
// Avoid propagating failures to Promises returned by later
|
|
776
|
-
// invocations of the iterator.
|
|
777
|
-
callInvokeWithMethodAndArg
|
|
778
|
-
) : callInvokeWithMethodAndArg();
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// Define the unified helper method that is used to implement .next,
|
|
782
|
-
// .throw, and .return (see defineIteratorMethods).
|
|
783
|
-
this._invoke = enqueue;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
defineIteratorMethods(AsyncIterator.prototype);
|
|
787
|
-
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
|
|
788
|
-
return this;
|
|
789
|
-
};
|
|
790
|
-
exports.AsyncIterator = AsyncIterator;
|
|
791
|
-
|
|
792
|
-
// Note that simple async functions are implemented on top of
|
|
793
|
-
// AsyncIterator objects; they just return a Promise for the value of
|
|
794
|
-
// the final result produced by the iterator.
|
|
795
|
-
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
796
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
797
|
-
|
|
798
|
-
var iter = new AsyncIterator(
|
|
799
|
-
wrap(innerFn, outerFn, self, tryLocsList),
|
|
800
|
-
PromiseImpl
|
|
801
|
-
);
|
|
802
|
-
|
|
803
|
-
return exports.isGeneratorFunction(outerFn)
|
|
804
|
-
? iter // If outerFn is a generator, return the full iterator.
|
|
805
|
-
: iter.next().then(function(result) {
|
|
806
|
-
return result.done ? result.value : iter.next();
|
|
807
|
-
});
|
|
808
|
-
};
|
|
809
|
-
|
|
810
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
811
|
-
var state = GenStateSuspendedStart;
|
|
812
|
-
|
|
813
|
-
return function invoke(method, arg) {
|
|
814
|
-
if (state === GenStateExecuting) {
|
|
815
|
-
throw new Error("Generator is already running");
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
if (state === GenStateCompleted) {
|
|
819
|
-
if (method === "throw") {
|
|
820
|
-
throw arg;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// Be forgiving, per 25.3.3.3.3 of the spec:
|
|
824
|
-
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
825
|
-
return doneResult();
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
context.method = method;
|
|
829
|
-
context.arg = arg;
|
|
830
|
-
|
|
831
|
-
while (true) {
|
|
832
|
-
var delegate = context.delegate;
|
|
833
|
-
if (delegate) {
|
|
834
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
835
|
-
if (delegateResult) {
|
|
836
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
837
|
-
return delegateResult;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
if (context.method === "next") {
|
|
842
|
-
// Setting context._sent for legacy support of Babel's
|
|
843
|
-
// function.sent implementation.
|
|
844
|
-
context.sent = context._sent = context.arg;
|
|
845
|
-
|
|
846
|
-
} else if (context.method === "throw") {
|
|
847
|
-
if (state === GenStateSuspendedStart) {
|
|
848
|
-
state = GenStateCompleted;
|
|
849
|
-
throw context.arg;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
context.dispatchException(context.arg);
|
|
853
|
-
|
|
854
|
-
} else if (context.method === "return") {
|
|
855
|
-
context.abrupt("return", context.arg);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
state = GenStateExecuting;
|
|
859
|
-
|
|
860
|
-
var record = tryCatch(innerFn, self, context);
|
|
861
|
-
if (record.type === "normal") {
|
|
862
|
-
// If an exception is thrown from innerFn, we leave state ===
|
|
863
|
-
// GenStateExecuting and loop back for another invocation.
|
|
864
|
-
state = context.done
|
|
865
|
-
? GenStateCompleted
|
|
866
|
-
: GenStateSuspendedYield;
|
|
867
|
-
|
|
868
|
-
if (record.arg === ContinueSentinel) {
|
|
869
|
-
continue;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
return {
|
|
873
|
-
value: record.arg,
|
|
874
|
-
done: context.done
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
} else if (record.type === "throw") {
|
|
878
|
-
state = GenStateCompleted;
|
|
879
|
-
// Dispatch the exception by looping back around to the
|
|
880
|
-
// context.dispatchException(context.arg) call above.
|
|
881
|
-
context.method = "throw";
|
|
882
|
-
context.arg = record.arg;
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
// Call delegate.iterator[context.method](context.arg) and handle the
|
|
889
|
-
// result, either by returning a { value, done } result from the
|
|
890
|
-
// delegate iterator, or by modifying context.method and context.arg,
|
|
891
|
-
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
892
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
893
|
-
var method = delegate.iterator[context.method];
|
|
894
|
-
if (method === undefined$1) {
|
|
895
|
-
// A .throw or .return when the delegate iterator has no .throw
|
|
896
|
-
// method always terminates the yield* loop.
|
|
897
|
-
context.delegate = null;
|
|
898
|
-
|
|
899
|
-
if (context.method === "throw") {
|
|
900
|
-
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
901
|
-
if (delegate.iterator["return"]) {
|
|
902
|
-
// If the delegate iterator has a return method, give it a
|
|
903
|
-
// chance to clean up.
|
|
904
|
-
context.method = "return";
|
|
905
|
-
context.arg = undefined$1;
|
|
906
|
-
maybeInvokeDelegate(delegate, context);
|
|
907
|
-
|
|
908
|
-
if (context.method === "throw") {
|
|
909
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
910
|
-
// "return" to "throw", let that override the TypeError below.
|
|
911
|
-
return ContinueSentinel;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
context.method = "throw";
|
|
916
|
-
context.arg = new TypeError(
|
|
917
|
-
"The iterator does not provide a 'throw' method");
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
return ContinueSentinel;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
924
|
-
|
|
925
|
-
if (record.type === "throw") {
|
|
926
|
-
context.method = "throw";
|
|
927
|
-
context.arg = record.arg;
|
|
928
|
-
context.delegate = null;
|
|
929
|
-
return ContinueSentinel;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
var info = record.arg;
|
|
933
|
-
|
|
934
|
-
if (! info) {
|
|
935
|
-
context.method = "throw";
|
|
936
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
937
|
-
context.delegate = null;
|
|
938
|
-
return ContinueSentinel;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
if (info.done) {
|
|
942
|
-
// Assign the result of the finished delegate to the temporary
|
|
943
|
-
// variable specified by delegate.resultName (see delegateYield).
|
|
944
|
-
context[delegate.resultName] = info.value;
|
|
945
|
-
|
|
946
|
-
// Resume execution at the desired location (see delegateYield).
|
|
947
|
-
context.next = delegate.nextLoc;
|
|
948
|
-
|
|
949
|
-
// If context.method was "throw" but the delegate handled the
|
|
950
|
-
// exception, let the outer generator proceed normally. If
|
|
951
|
-
// context.method was "next", forget context.arg since it has been
|
|
952
|
-
// "consumed" by the delegate iterator. If context.method was
|
|
953
|
-
// "return", allow the original .return call to continue in the
|
|
954
|
-
// outer generator.
|
|
955
|
-
if (context.method !== "return") {
|
|
956
|
-
context.method = "next";
|
|
957
|
-
context.arg = undefined$1;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
} else {
|
|
961
|
-
// Re-yield the result returned by the delegate method.
|
|
962
|
-
return info;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
// The delegate iterator is finished, so forget it and continue with
|
|
966
|
-
// the outer generator.
|
|
967
|
-
context.delegate = null;
|
|
968
|
-
return ContinueSentinel;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
972
|
-
// unified ._invoke helper method.
|
|
973
|
-
defineIteratorMethods(Gp);
|
|
974
|
-
|
|
975
|
-
define(Gp, toStringTagSymbol, "Generator");
|
|
976
|
-
|
|
977
|
-
// A Generator should always return itself as the iterator object when the
|
|
978
|
-
// @@iterator function is called on it. Some browsers' implementations of the
|
|
979
|
-
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
980
|
-
// object to not be returned from this call. This ensures that doesn't happen.
|
|
981
|
-
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
982
|
-
Gp[iteratorSymbol] = function() {
|
|
983
|
-
return this;
|
|
984
|
-
};
|
|
985
|
-
|
|
986
|
-
Gp.toString = function() {
|
|
987
|
-
return "[object Generator]";
|
|
988
|
-
};
|
|
989
|
-
|
|
990
|
-
function pushTryEntry(locs) {
|
|
991
|
-
var entry = { tryLoc: locs[0] };
|
|
992
|
-
|
|
993
|
-
if (1 in locs) {
|
|
994
|
-
entry.catchLoc = locs[1];
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
if (2 in locs) {
|
|
998
|
-
entry.finallyLoc = locs[2];
|
|
999
|
-
entry.afterLoc = locs[3];
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
this.tryEntries.push(entry);
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
function resetTryEntry(entry) {
|
|
1006
|
-
var record = entry.completion || {};
|
|
1007
|
-
record.type = "normal";
|
|
1008
|
-
delete record.arg;
|
|
1009
|
-
entry.completion = record;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
function Context(tryLocsList) {
|
|
1013
|
-
// The root entry object (effectively a try statement without a catch
|
|
1014
|
-
// or a finally block) gives us a place to store values thrown from
|
|
1015
|
-
// locations where there is no enclosing try statement.
|
|
1016
|
-
this.tryEntries = [{ tryLoc: "root" }];
|
|
1017
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
1018
|
-
this.reset(true);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
exports.keys = function(object) {
|
|
1022
|
-
var keys = [];
|
|
1023
|
-
for (var key in object) {
|
|
1024
|
-
keys.push(key);
|
|
1025
|
-
}
|
|
1026
|
-
keys.reverse();
|
|
1027
|
-
|
|
1028
|
-
// Rather than returning an object with a next method, we keep
|
|
1029
|
-
// things simple and return the next function itself.
|
|
1030
|
-
return function next() {
|
|
1031
|
-
while (keys.length) {
|
|
1032
|
-
var key = keys.pop();
|
|
1033
|
-
if (key in object) {
|
|
1034
|
-
next.value = key;
|
|
1035
|
-
next.done = false;
|
|
1036
|
-
return next;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
// To avoid creating an additional object, we just hang the .value
|
|
1041
|
-
// and .done properties off the next function object itself. This
|
|
1042
|
-
// also ensures that the minifier will not anonymize the function.
|
|
1043
|
-
next.done = true;
|
|
1044
|
-
return next;
|
|
1045
|
-
};
|
|
1046
|
-
};
|
|
1047
|
-
|
|
1048
|
-
function values(iterable) {
|
|
1049
|
-
if (iterable) {
|
|
1050
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
1051
|
-
if (iteratorMethod) {
|
|
1052
|
-
return iteratorMethod.call(iterable);
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
if (typeof iterable.next === "function") {
|
|
1056
|
-
return iterable;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
if (!isNaN(iterable.length)) {
|
|
1060
|
-
var i = -1, next = function next() {
|
|
1061
|
-
while (++i < iterable.length) {
|
|
1062
|
-
if (hasOwn.call(iterable, i)) {
|
|
1063
|
-
next.value = iterable[i];
|
|
1064
|
-
next.done = false;
|
|
1065
|
-
return next;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
next.value = undefined$1;
|
|
1070
|
-
next.done = true;
|
|
1071
|
-
|
|
1072
|
-
return next;
|
|
1073
|
-
};
|
|
1074
|
-
|
|
1075
|
-
return next.next = next;
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
// Return an iterator with no values.
|
|
1080
|
-
return { next: doneResult };
|
|
1081
|
-
}
|
|
1082
|
-
exports.values = values;
|
|
1083
|
-
|
|
1084
|
-
function doneResult() {
|
|
1085
|
-
return { value: undefined$1, done: true };
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
Context.prototype = {
|
|
1089
|
-
constructor: Context,
|
|
1090
|
-
|
|
1091
|
-
reset: function(skipTempReset) {
|
|
1092
|
-
this.prev = 0;
|
|
1093
|
-
this.next = 0;
|
|
1094
|
-
// Resetting context._sent for legacy support of Babel's
|
|
1095
|
-
// function.sent implementation.
|
|
1096
|
-
this.sent = this._sent = undefined$1;
|
|
1097
|
-
this.done = false;
|
|
1098
|
-
this.delegate = null;
|
|
1099
|
-
|
|
1100
|
-
this.method = "next";
|
|
1101
|
-
this.arg = undefined$1;
|
|
1102
|
-
|
|
1103
|
-
this.tryEntries.forEach(resetTryEntry);
|
|
1104
|
-
|
|
1105
|
-
if (!skipTempReset) {
|
|
1106
|
-
for (var name in this) {
|
|
1107
|
-
// Not sure about the optimal order of these conditions:
|
|
1108
|
-
if (name.charAt(0) === "t" &&
|
|
1109
|
-
hasOwn.call(this, name) &&
|
|
1110
|
-
!isNaN(+name.slice(1))) {
|
|
1111
|
-
this[name] = undefined$1;
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
},
|
|
1116
|
-
|
|
1117
|
-
stop: function() {
|
|
1118
|
-
this.done = true;
|
|
1119
|
-
|
|
1120
|
-
var rootEntry = this.tryEntries[0];
|
|
1121
|
-
var rootRecord = rootEntry.completion;
|
|
1122
|
-
if (rootRecord.type === "throw") {
|
|
1123
|
-
throw rootRecord.arg;
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
return this.rval;
|
|
1127
|
-
},
|
|
1128
|
-
|
|
1129
|
-
dispatchException: function(exception) {
|
|
1130
|
-
if (this.done) {
|
|
1131
|
-
throw exception;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
var context = this;
|
|
1135
|
-
function handle(loc, caught) {
|
|
1136
|
-
record.type = "throw";
|
|
1137
|
-
record.arg = exception;
|
|
1138
|
-
context.next = loc;
|
|
1139
|
-
|
|
1140
|
-
if (caught) {
|
|
1141
|
-
// If the dispatched exception was caught by a catch block,
|
|
1142
|
-
// then let that catch block handle the exception normally.
|
|
1143
|
-
context.method = "next";
|
|
1144
|
-
context.arg = undefined$1;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
return !! caught;
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1151
|
-
var entry = this.tryEntries[i];
|
|
1152
|
-
var record = entry.completion;
|
|
1153
|
-
|
|
1154
|
-
if (entry.tryLoc === "root") {
|
|
1155
|
-
// Exception thrown outside of any try block that could handle
|
|
1156
|
-
// it, so set the completion value of the entire function to
|
|
1157
|
-
// throw the exception.
|
|
1158
|
-
return handle("end");
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
if (entry.tryLoc <= this.prev) {
|
|
1162
|
-
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
1163
|
-
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
1164
|
-
|
|
1165
|
-
if (hasCatch && hasFinally) {
|
|
1166
|
-
if (this.prev < entry.catchLoc) {
|
|
1167
|
-
return handle(entry.catchLoc, true);
|
|
1168
|
-
} else if (this.prev < entry.finallyLoc) {
|
|
1169
|
-
return handle(entry.finallyLoc);
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
} else if (hasCatch) {
|
|
1173
|
-
if (this.prev < entry.catchLoc) {
|
|
1174
|
-
return handle(entry.catchLoc, true);
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
} else if (hasFinally) {
|
|
1178
|
-
if (this.prev < entry.finallyLoc) {
|
|
1179
|
-
return handle(entry.finallyLoc);
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
} else {
|
|
1183
|
-
throw new Error("try statement without catch or finally");
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
},
|
|
1188
|
-
|
|
1189
|
-
abrupt: function(type, arg) {
|
|
1190
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1191
|
-
var entry = this.tryEntries[i];
|
|
1192
|
-
if (entry.tryLoc <= this.prev &&
|
|
1193
|
-
hasOwn.call(entry, "finallyLoc") &&
|
|
1194
|
-
this.prev < entry.finallyLoc) {
|
|
1195
|
-
var finallyEntry = entry;
|
|
1196
|
-
break;
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
if (finallyEntry &&
|
|
1201
|
-
(type === "break" ||
|
|
1202
|
-
type === "continue") &&
|
|
1203
|
-
finallyEntry.tryLoc <= arg &&
|
|
1204
|
-
arg <= finallyEntry.finallyLoc) {
|
|
1205
|
-
// Ignore the finally entry if control is not jumping to a
|
|
1206
|
-
// location outside the try/catch block.
|
|
1207
|
-
finallyEntry = null;
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
1211
|
-
record.type = type;
|
|
1212
|
-
record.arg = arg;
|
|
1213
|
-
|
|
1214
|
-
if (finallyEntry) {
|
|
1215
|
-
this.method = "next";
|
|
1216
|
-
this.next = finallyEntry.finallyLoc;
|
|
1217
|
-
return ContinueSentinel;
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
return this.complete(record);
|
|
1221
|
-
},
|
|
1222
|
-
|
|
1223
|
-
complete: function(record, afterLoc) {
|
|
1224
|
-
if (record.type === "throw") {
|
|
1225
|
-
throw record.arg;
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
if (record.type === "break" ||
|
|
1229
|
-
record.type === "continue") {
|
|
1230
|
-
this.next = record.arg;
|
|
1231
|
-
} else if (record.type === "return") {
|
|
1232
|
-
this.rval = this.arg = record.arg;
|
|
1233
|
-
this.method = "return";
|
|
1234
|
-
this.next = "end";
|
|
1235
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
1236
|
-
this.next = afterLoc;
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
return ContinueSentinel;
|
|
1240
|
-
},
|
|
1241
|
-
|
|
1242
|
-
finish: function(finallyLoc) {
|
|
1243
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1244
|
-
var entry = this.tryEntries[i];
|
|
1245
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
1246
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
1247
|
-
resetTryEntry(entry);
|
|
1248
|
-
return ContinueSentinel;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
},
|
|
1252
|
-
|
|
1253
|
-
"catch": function(tryLoc) {
|
|
1254
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1255
|
-
var entry = this.tryEntries[i];
|
|
1256
|
-
if (entry.tryLoc === tryLoc) {
|
|
1257
|
-
var record = entry.completion;
|
|
1258
|
-
if (record.type === "throw") {
|
|
1259
|
-
var thrown = record.arg;
|
|
1260
|
-
resetTryEntry(entry);
|
|
1261
|
-
}
|
|
1262
|
-
return thrown;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
// The context.catch method must only be called with a location
|
|
1267
|
-
// argument that corresponds to a known catch block.
|
|
1268
|
-
throw new Error("illegal catch attempt");
|
|
1269
|
-
},
|
|
1270
|
-
|
|
1271
|
-
delegateYield: function(iterable, resultName, nextLoc) {
|
|
1272
|
-
this.delegate = {
|
|
1273
|
-
iterator: values(iterable),
|
|
1274
|
-
resultName: resultName,
|
|
1275
|
-
nextLoc: nextLoc
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
|
-
if (this.method === "next") {
|
|
1279
|
-
// Deliberately forget the last sent value so that we don't
|
|
1280
|
-
// accidentally pass it on to the delegate.
|
|
1281
|
-
this.arg = undefined$1;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
return ContinueSentinel;
|
|
1285
|
-
}
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
|
-
// Regardless of whether this script is executing as a CommonJS module
|
|
1289
|
-
// or not, return the runtime object so that we can declare the variable
|
|
1290
|
-
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
1291
|
-
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
1292
|
-
return exports;
|
|
1293
|
-
|
|
1294
|
-
}(
|
|
1295
|
-
// If this script is executing as a CommonJS module, use module.exports
|
|
1296
|
-
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
1297
|
-
// object. Either way, the resulting object will be used to initialize
|
|
1298
|
-
// the regeneratorRuntime variable at the top of this file.
|
|
1299
|
-
module.exports
|
|
1300
|
-
));
|
|
1301
|
-
|
|
1302
|
-
try {
|
|
1303
|
-
regeneratorRuntime = runtime;
|
|
1304
|
-
} catch (accidentalStrictMode) {
|
|
1305
|
-
// This module should not be running in strict mode, so the above
|
|
1306
|
-
// assignment should always work unless something is misconfigured. Just
|
|
1307
|
-
// in case runtime.js accidentally runs in strict mode, we can escape
|
|
1308
|
-
// strict mode using a global Function call. This could conceivably fail
|
|
1309
|
-
// if a Content Security Policy forbids using Function, but in that case
|
|
1310
|
-
// the proper solution is to fix the accidental strict mode problem. If
|
|
1311
|
-
// you've misconfigured your bundler to force strict mode and applied a
|
|
1312
|
-
// CSP to forbid Function, and you're not willing to fix either of those
|
|
1313
|
-
// problems, please detail your unique predicament in a GitHub issue.
|
|
1314
|
-
Function("r", "regeneratorRuntime = r")(runtime);
|
|
1315
|
-
}
|
|
1316
|
-
});
|
|
1317
|
-
|
|
1318
|
-
var Task;
|
|
1319
|
-
|
|
1320
|
-
(function (Task) {
|
|
1321
|
-
/**
|
|
1322
|
-
* Custom task monad constructor
|
|
1323
|
-
*
|
|
1324
|
-
* @template R returned task's resolve type
|
|
1325
|
-
* @param invoke promise defining task execution
|
|
1326
|
-
* @param cancel cancelation function
|
|
1327
|
-
* @returns task resolving to resolve value of invoke
|
|
1328
|
-
*
|
|
1329
|
-
* @note low-level primitive for creating custom tasks, not intended for general use
|
|
1330
|
-
*/
|
|
1331
|
-
function create(invoke, cancel) {
|
|
1332
|
-
return new TaskClass(invoke, cancel);
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
Task.create = create;
|
|
1336
|
-
/**
|
|
1337
|
-
* Invariant task constructor creating resolved task from plain value
|
|
1338
|
-
*
|
|
1339
|
-
* @template R returned task's resolve type
|
|
1340
|
-
* @param value value to be returned upon awaiting
|
|
1341
|
-
* @returns task resolving to specified value
|
|
1342
|
-
*/
|
|
1343
|
-
|
|
1344
|
-
function resolved(value) {
|
|
1345
|
-
return Task.create(Promise.resolve(Maybe.just(Either.right(value))), function () {});
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
Task.resolved = resolved;
|
|
1349
|
-
/**
|
|
1350
|
-
* Invariant task constructor creating rejected task from error value
|
|
1351
|
-
*
|
|
1352
|
-
* @template R returned task's resolve type
|
|
1353
|
-
* @param error error to be returned upon awaiting
|
|
1354
|
-
* @returns task resolving to specified value
|
|
1355
|
-
*/
|
|
1356
|
-
|
|
1357
|
-
function rejected(error) {
|
|
1358
|
-
return Task.create(Promise.resolve(Maybe.just(Either.left(error))), function () {});
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
Task.rejected = rejected;
|
|
1362
|
-
/**
|
|
1363
|
-
* Invariant task constructor creating canceled task
|
|
1364
|
-
*
|
|
1365
|
-
* @template R returned task's resolve type
|
|
1366
|
-
* @returns task resolving to specified value
|
|
1367
|
-
*/
|
|
1368
|
-
|
|
1369
|
-
function canceled() {
|
|
1370
|
-
return Task.create(Promise.resolve(Maybe.nothing()), function () {});
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
Task.canceled = canceled;
|
|
1374
|
-
/**
|
|
1375
|
-
* Lift from promise to task resolving to that promise result
|
|
1376
|
-
*
|
|
1377
|
-
* Userfull for converting promises to tasks
|
|
1378
|
-
* If converted task is canceled or failed externally return value will be ignored without side-effects
|
|
1379
|
-
* All tasks are no-trowing by default, any occured errors are returned as Left<any>
|
|
1380
|
-
*
|
|
1381
|
-
* @template R returned task resolve type
|
|
1382
|
-
* @param promise promise to be resolved
|
|
1383
|
-
* @returns task resolving to specified promise value
|
|
1384
|
-
*
|
|
1385
|
-
* @example
|
|
1386
|
-
* ```typescript
|
|
1387
|
-
* const task = Task.fromPromise(someAsyncOperation('someData')).map((result) => result.length);
|
|
1388
|
-
* ```
|
|
1389
|
-
*/
|
|
1390
|
-
|
|
1391
|
-
function fromPromise(promise) {
|
|
1392
|
-
var _resolver = resolver(),
|
|
1393
|
-
resolve = _resolver[0],
|
|
1394
|
-
setResolve = _resolver[1];
|
|
1395
|
-
|
|
1396
|
-
return Task.create(new Promise(function (_resolve) {
|
|
1397
|
-
setResolve(_resolve);
|
|
1398
|
-
promise.then(Either.right, Either.left).then(Maybe.just).then(resolve);
|
|
1399
|
-
}), function (error) {
|
|
1400
|
-
return resolve(error.map(Either.left));
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
Task.fromPromise = fromPromise;
|
|
1405
|
-
/**
|
|
1406
|
-
* Lift from sync function to task resolving to said function result
|
|
1407
|
-
*
|
|
1408
|
-
* Generally, functions are not considered tasks as they cannot be interrupted in any way
|
|
1409
|
-
* However there may be cases when impure function performs actions leading to cancelling or failing the task they are called from
|
|
1410
|
-
* Without such wrapper such cases would lead to ignoring said cancelation and continuilg task chain
|
|
1411
|
-
* This function is mostly used internally and is not expected to be widely used except of some edge scenarios
|
|
1412
|
-
*
|
|
1413
|
-
* If converted task is canceled or failed externally return value will be ignored without side-effects
|
|
1414
|
-
* All tasks are no-trowing by default, any occured errors are returned as Left<any>
|
|
1415
|
-
*
|
|
1416
|
-
* @template R returned task resolve type
|
|
1417
|
-
* @param producer function to be wrapped to a task
|
|
1418
|
-
* @param cancelRef reference object allowing to set cancelation function prior to invoking function
|
|
1419
|
-
* @returns task resolving to the specified function's result
|
|
1420
|
-
*
|
|
1421
|
-
* @example
|
|
1422
|
-
* ```typescript
|
|
1423
|
-
* const cancelRef = { cancel: () => {} };
|
|
1424
|
-
*
|
|
1425
|
-
* const task = Task.fromFunction(() => someFunction('someData'), cancelRef).map((result) => result.length);
|
|
1426
|
-
* ```
|
|
1427
|
-
*/
|
|
1428
|
-
|
|
1429
|
-
function fromFunction(producer, cancelRef) {
|
|
1430
|
-
var _resolver2 = resolver(),
|
|
1431
|
-
resolve = _resolver2[0],
|
|
1432
|
-
setResolve = _resolver2[1];
|
|
1433
|
-
|
|
1434
|
-
var cancel = function cancel(error) {
|
|
1435
|
-
return resolve(error.map(Either.left));
|
|
1436
|
-
};
|
|
1437
|
-
|
|
1438
|
-
cancelRef.cancel = cancel;
|
|
1439
|
-
return Task.create(new Promise(function (_resolve) {
|
|
1440
|
-
setResolve(_resolve);
|
|
1441
|
-
|
|
1442
|
-
try {
|
|
1443
|
-
resolve(Maybe.just(Either.right(producer())));
|
|
1444
|
-
} catch (e) {
|
|
1445
|
-
resolve(Maybe.just(Either.left(e)));
|
|
1446
|
-
}
|
|
1447
|
-
}), cancel);
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
Task.fromFunction = fromFunction;
|
|
1451
|
-
/**
|
|
1452
|
-
* Convinience shortcut for yielding async functions as tasks
|
|
1453
|
-
*
|
|
1454
|
-
* @template R returned generator resolve type
|
|
1455
|
-
* @param promise promise to be resolved
|
|
1456
|
-
* @returns generator to be be used with yield*
|
|
1457
|
-
*/
|
|
1458
|
-
|
|
1459
|
-
function promiseGenerator(promise) {
|
|
1460
|
-
return Task.fromPromise(promise).generator();
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
Task.promiseGenerator = promiseGenerator;
|
|
1464
|
-
/**
|
|
1465
|
-
* Lift from function returning value/promise to function returning task resolving to that value
|
|
1466
|
-
*
|
|
1467
|
-
* Userfull for converting exising async functions to task functions for further use
|
|
1468
|
-
*
|
|
1469
|
-
* @template A returned function's argument types
|
|
1470
|
-
* @template R returned function's result task's resolve type
|
|
1471
|
-
* @param promiseFunction function returning promise or plain value to be resolved
|
|
1472
|
-
* @returns task function wrapping specified promise function
|
|
1473
|
-
* @see Task.fromPromise
|
|
1474
|
-
*
|
|
1475
|
-
* @example
|
|
1476
|
-
* ```typescript
|
|
1477
|
-
* const taskFunction = liftPromiseFunction(someAsyncOperation);
|
|
1478
|
-
*
|
|
1479
|
-
* const task = taskFunction('someData').map((result) => result.length);
|
|
1480
|
-
* ```
|
|
1481
|
-
*/
|
|
1482
|
-
|
|
1483
|
-
function lift(promiseFunction) {
|
|
1484
|
-
return function () {
|
|
1485
|
-
return Task.fromPromise(promiseFunction.apply(void 0, arguments));
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
Task.lift = lift;
|
|
1490
|
-
/**
|
|
1491
|
-
* Create compound task from generator function
|
|
1492
|
-
*
|
|
1493
|
-
* Applying yield to task within the generator function awaits the task and returns underlying value in case of success
|
|
1494
|
-
* However the convinient option for typescript is to use ```yield* task.generator()``` as othervise one may have to deal with union types
|
|
1495
|
-
*
|
|
1496
|
-
* In case of failure an error is thrown and may be caught by try-catch
|
|
1497
|
-
*
|
|
1498
|
-
* If error is not caught the task is interrupted and returns 'just left error' immediately. In case of cancelation the task is interrupted and returns 'nothing' immediately
|
|
1499
|
-
*
|
|
1500
|
-
* @template TT yielded task type
|
|
1501
|
-
* @template R returned task resolve type
|
|
1502
|
-
* @param taskGeneratorFunction task generator function
|
|
1503
|
-
* @returns task resolving to generator's return type
|
|
1504
|
-
*
|
|
1505
|
-
* @note compound task execution is interrupted only at yield statements, so despite returning immediately any promise-based chains would continue running until the first yield
|
|
1506
|
-
* @note due to type unpredictability you HAVE to use ```.generator()``` together with yield* to avoid type issues, despite the fact that task may be yielded directly
|
|
1507
|
-
*
|
|
1508
|
-
* @example
|
|
1509
|
-
* ```typescript
|
|
1510
|
-
* const task = Task.generate(function*() {
|
|
1511
|
-
* try {
|
|
1512
|
-
* const value1 = yield* delayedValueTask('data', 400).generator();
|
|
1513
|
-
*
|
|
1514
|
-
* const value2 = yield* delayedValueTask(value1.length, 300).generator();
|
|
1515
|
-
*
|
|
1516
|
-
* return value2;
|
|
1517
|
-
* } catch (e) {
|
|
1518
|
-
* return -1;
|
|
1519
|
-
* }
|
|
1520
|
-
* });
|
|
1521
|
-
* ```
|
|
1522
|
-
*/
|
|
1523
|
-
|
|
1524
|
-
function generate(taskGeneratorFunction) {
|
|
1525
|
-
var generator = taskGeneratorFunction();
|
|
1526
|
-
|
|
1527
|
-
var sequentor = function sequentor(next) {
|
|
1528
|
-
return next.done ? Task.resolved(next.value) : next.value.matchChain({
|
|
1529
|
-
resolved: function resolved(value) {
|
|
1530
|
-
return sequentor(generator.next(value));
|
|
1531
|
-
},
|
|
1532
|
-
rejected: function rejected(error) {
|
|
1533
|
-
return sequentor(generator["throw"](error));
|
|
1534
|
-
},
|
|
1535
|
-
canceled: Task.canceled
|
|
1536
|
-
});
|
|
1537
|
-
};
|
|
1538
|
-
|
|
1539
|
-
return Task.resolved(undefined).chain(function () {
|
|
1540
|
-
return sequentor(generator.next());
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
Task.generate = generate;
|
|
1545
|
-
/**
|
|
1546
|
-
* Generic timeout task
|
|
1547
|
-
*
|
|
1548
|
-
* Usefull for creating delays in task chains or implementing limiting tasks
|
|
1549
|
-
*
|
|
1550
|
-
* @param delay duration in ms after that the task resolves to void
|
|
1551
|
-
* @returns task resolving to void (undefined) after specified delay
|
|
1552
|
-
*
|
|
1553
|
-
* @example
|
|
1554
|
-
* ```typescript
|
|
1555
|
-
* const delayedValueTask = <T>(value: T, delay: number) => Task.timeout(delay).map(() => value);
|
|
1556
|
-
* // ... //
|
|
1557
|
-
* const value = yield* delayedValueTask(42, 1000).generator();
|
|
1558
|
-
*
|
|
1559
|
-
* console.log("It's past 1 second and here's a value:", value)
|
|
1560
|
-
* ```
|
|
1561
|
-
*/
|
|
1562
|
-
|
|
1563
|
-
function timeout(delay) {
|
|
1564
|
-
return fromCallback(function (resolve) {
|
|
1565
|
-
return setTimeout(function () {
|
|
1566
|
-
return resolve();
|
|
1567
|
-
}, delay);
|
|
1568
|
-
}, clearTimeout);
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
Task.timeout = timeout;
|
|
1572
|
-
/**
|
|
1573
|
-
* Generic callback task
|
|
1574
|
-
*
|
|
1575
|
-
* Usefull for creating custom tasks from success and error callbacks and cancelaton function. Synchronous callbacks are not supported, @see fromFuction
|
|
1576
|
-
*
|
|
1577
|
-
* @param create task body with success and error callbacks
|
|
1578
|
-
* @param cancel cancelation function intended for stopping task execution
|
|
1579
|
-
* @returns task resolving to success value
|
|
1580
|
-
*
|
|
1581
|
-
* @example
|
|
1582
|
-
* ```typescript
|
|
1583
|
-
* export function timeout(delay: number) {
|
|
1584
|
-
* return fromCallback<NodeJS.Timeout, void>((resolve) => setTimeout(() => resolve(), delay), clearTimeout);
|
|
1585
|
-
* }
|
|
1586
|
-
* ```
|
|
1587
|
-
*/
|
|
1588
|
-
|
|
1589
|
-
function fromCallback(create, cancel) {
|
|
1590
|
-
var handler;
|
|
1591
|
-
|
|
1592
|
-
var _resolver3 = resolver(),
|
|
1593
|
-
resolve = _resolver3[0],
|
|
1594
|
-
setResolve = _resolver3[1];
|
|
1595
|
-
|
|
1596
|
-
return Task.create(new Promise(function (_resolve) {
|
|
1597
|
-
setResolve(_resolve);
|
|
1598
|
-
handler = create(function (r) {
|
|
1599
|
-
return resolve(Maybe.just(Either.right(r)));
|
|
1600
|
-
}, function (e) {
|
|
1601
|
-
return resolve(Maybe.just(Either.left(e)));
|
|
1602
|
-
});
|
|
1603
|
-
}), function (error) {
|
|
1604
|
-
resolve(error.map(Either.left));
|
|
1605
|
-
cancel(handler);
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
Task.fromCallback = fromCallback;
|
|
1610
|
-
/**
|
|
1611
|
-
* Start multiple tasks one after another
|
|
1612
|
-
*
|
|
1613
|
-
* @param taskFunctions list of task functions (without arguments)
|
|
1614
|
-
* @returns composite task invoring every task in order and resolving to the list of results
|
|
1615
|
-
*/
|
|
1616
|
-
|
|
1617
|
-
function sequence(taskFunctions) {
|
|
1618
|
-
return Array.from(taskFunctions).reduce(function (prev, taskFunction) {
|
|
1619
|
-
return prev.chain(function (list) {
|
|
1620
|
-
return taskFunction().map(function (value) {
|
|
1621
|
-
return list.concat(value);
|
|
1622
|
-
});
|
|
1623
|
-
});
|
|
1624
|
-
}, Task.resolved([]));
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
Task.sequence = sequence;
|
|
1628
|
-
/**
|
|
1629
|
-
* Execute all tasks in parallel and return list of results
|
|
1630
|
-
*
|
|
1631
|
-
* Resulting task resolves when all tasks are resolved, returning list of tasks results maintaining result order
|
|
1632
|
-
* In case of failure (external or internal) resulting task is immediately immediately rejected with that error and all pending tasks are canceled
|
|
1633
|
-
* In case of cancelation resulting task is immediately immediately canceled together with all pending tasks
|
|
1634
|
-
*
|
|
1635
|
-
* @note direct equivalent of Promise.all
|
|
1636
|
-
*
|
|
1637
|
-
* @template T underlying task type
|
|
1638
|
-
* @param tasks iterable of tasks to execute
|
|
1639
|
-
* @retuirns task resolving to the list of results
|
|
1640
|
-
*/
|
|
1641
|
-
|
|
1642
|
-
function all(tasks) {
|
|
1643
|
-
var _resolver4 = resolver(),
|
|
1644
|
-
resolve = _resolver4[0],
|
|
1645
|
-
setResolve = _resolver4[1];
|
|
1646
|
-
|
|
1647
|
-
var taskArray = Array.from(tasks);
|
|
1648
|
-
|
|
1649
|
-
var cancel = function cancel(error) {
|
|
1650
|
-
return taskArray.forEach(function (task) {
|
|
1651
|
-
return task._cancel(error);
|
|
1652
|
-
});
|
|
1653
|
-
};
|
|
1654
|
-
|
|
1655
|
-
var list = taskArray.map(Maybe.nothing);
|
|
1656
|
-
|
|
1657
|
-
var _resolved = function resolved(value, i) {
|
|
1658
|
-
list[i] = Maybe.just(value);
|
|
1659
|
-
|
|
1660
|
-
if (Maybe.everyJust(list)) {
|
|
1661
|
-
resolve(Maybe.just(Either.right(list.map(Just.just))));
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
|
|
1665
|
-
var _rejected = function rejected(error) {
|
|
1666
|
-
resolve(error.map(Either.left));
|
|
1667
|
-
cancel(error);
|
|
1668
|
-
};
|
|
1669
|
-
|
|
1670
|
-
return Task.create(new Promise(function (_resolve) {
|
|
1671
|
-
setResolve(_resolve);
|
|
1672
|
-
taskArray.map(function (task, i) {
|
|
1673
|
-
return task.matchTap({
|
|
1674
|
-
resolved: function resolved(value) {
|
|
1675
|
-
return _resolved(value, i);
|
|
1676
|
-
},
|
|
1677
|
-
rejected: function rejected(error) {
|
|
1678
|
-
return _rejected(Maybe.just(error));
|
|
1679
|
-
},
|
|
1680
|
-
canceled: function canceled() {
|
|
1681
|
-
return _rejected(Maybe.nothing());
|
|
1682
|
-
}
|
|
1683
|
-
});
|
|
1684
|
-
});
|
|
1685
|
-
}), cancel);
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
Task.all = all;
|
|
1689
|
-
/**
|
|
1690
|
-
* Execute all tasks in parallel and return the result of the first successful one
|
|
1691
|
-
*
|
|
1692
|
-
* Resulting task resolves when the first tasks is successfuly resolved, returning it's result
|
|
1693
|
-
* In case of external task rejecttion all tasks are rejected with that error and resulting task is rejected with an array of errors
|
|
1694
|
-
* In case of internal task rejection the execution is continued untill fthe first task resolves succesfully or all the tasks are rejected this way resulting task is rejected with an array of errors
|
|
1695
|
-
* In case of cancelation resulting task is immediately immediately canceled together with all pending tasks
|
|
1696
|
-
*
|
|
1697
|
-
* @note direct equivalent of Promise.any
|
|
1698
|
-
*
|
|
1699
|
-
* @template T underlying task type
|
|
1700
|
-
* @param tasks iterable of tasks to execute
|
|
1701
|
-
* @retuirns task resolving to the result of first successfull task
|
|
1702
|
-
*/
|
|
1703
|
-
|
|
1704
|
-
function any(tasks) {
|
|
1705
|
-
var _resolver5 = resolver(),
|
|
1706
|
-
resolve = _resolver5[0],
|
|
1707
|
-
setResolve = _resolver5[1];
|
|
1708
|
-
|
|
1709
|
-
var taskArray = Array.from(tasks);
|
|
1710
|
-
|
|
1711
|
-
var cancel = function cancel(error) {
|
|
1712
|
-
return taskArray.forEach(function (task) {
|
|
1713
|
-
return task._cancel(error);
|
|
1714
|
-
});
|
|
1715
|
-
};
|
|
1716
|
-
|
|
1717
|
-
var list = taskArray.map(Maybe.nothing);
|
|
1718
|
-
|
|
1719
|
-
var _resolved2 = function resolved(value) {
|
|
1720
|
-
resolve(value.map(Either.right));
|
|
1721
|
-
cancel(Maybe.nothing());
|
|
1722
|
-
};
|
|
1723
|
-
|
|
1724
|
-
var _rejected2 = function rejected(error, i) {
|
|
1725
|
-
list[i] = Maybe.just(error);
|
|
1726
|
-
|
|
1727
|
-
if (Maybe.everyJust(list)) {
|
|
1728
|
-
resolve(Maybe.just(Either.left(list.map(Just.just))));
|
|
1729
|
-
}
|
|
1730
|
-
};
|
|
1731
|
-
|
|
1732
|
-
return Task.create(new Promise(function (_resolve) {
|
|
1733
|
-
setResolve(_resolve);
|
|
1734
|
-
taskArray.map(function (task, i) {
|
|
1735
|
-
return task.matchTap({
|
|
1736
|
-
resolved: function resolved(value) {
|
|
1737
|
-
return _resolved2(Maybe.just(value));
|
|
1738
|
-
},
|
|
1739
|
-
rejected: function rejected(error) {
|
|
1740
|
-
return _rejected2(error, i);
|
|
1741
|
-
},
|
|
1742
|
-
canceled: function canceled() {
|
|
1743
|
-
return _resolved2(Maybe.nothing());
|
|
1744
|
-
}
|
|
1745
|
-
});
|
|
1746
|
-
});
|
|
1747
|
-
}), cancel);
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
Task.any = any;
|
|
1751
|
-
/**
|
|
1752
|
-
* Limit task execution based on another task
|
|
1753
|
-
*
|
|
1754
|
-
* If the second task resolves sooner than the first, resulting task is canceled
|
|
1755
|
-
* Otherwise the resulting task resolves together with the first one
|
|
1756
|
-
*
|
|
1757
|
-
* @param task task to limit
|
|
1758
|
-
* @param limitTask limiting task
|
|
1759
|
-
* @returns task limites according to limitTask
|
|
1760
|
-
*/
|
|
1761
|
-
|
|
1762
|
-
function limit(task, limitTask) {
|
|
1763
|
-
return Task.any([task, limitTask.chain(Task.canceled)]).chainRejected(function (errors) {
|
|
1764
|
-
return Task.rejected(errors[0]);
|
|
1765
|
-
});
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
Task.limit = limit;
|
|
1769
|
-
/**
|
|
1770
|
-
* Repeat task untill successful
|
|
1771
|
-
*
|
|
1772
|
-
* Given task is re-generated in case of failure (both external and internal)
|
|
1773
|
-
* Resulting task is still cancelable by standard means
|
|
1774
|
-
*
|
|
1775
|
-
* @param taskFunction task preoducing function
|
|
1776
|
-
*/
|
|
1777
|
-
|
|
1778
|
-
function repeat(taskFunction) {
|
|
1779
|
-
var sequentor = function sequentor() {
|
|
1780
|
-
return taskFunction().chainRejected(sequentor);
|
|
1781
|
-
};
|
|
1782
|
-
|
|
1783
|
-
return sequentor();
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
Task.repeat = repeat;
|
|
1787
|
-
})(Task || (Task = {}));
|
|
1788
|
-
|
|
1789
|
-
var resolver = function resolver() {
|
|
1790
|
-
var stub = function stub(_) {};
|
|
1791
|
-
|
|
1792
|
-
var globalResolve = stub;
|
|
1793
|
-
|
|
1794
|
-
var resolve = function resolve(value) {
|
|
1795
|
-
var r = globalResolve;
|
|
1796
|
-
globalResolve = stub;
|
|
1797
|
-
r(value);
|
|
1798
|
-
};
|
|
1799
|
-
|
|
1800
|
-
var setResolve = function setResolve(value) {
|
|
1801
|
-
globalResolve = value;
|
|
1802
|
-
};
|
|
1803
|
-
|
|
1804
|
-
return [resolve, setResolve];
|
|
1805
|
-
};
|
|
1806
|
-
|
|
1807
|
-
function chainTaskMaybe(_task, op) {
|
|
1808
|
-
var globalCancel = {
|
|
1809
|
-
cancel: _task._cancel
|
|
1810
|
-
};
|
|
1811
|
-
return Task.create(_task._invoke.then( /*#__PURE__*/function () {
|
|
1812
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(result) {
|
|
1813
|
-
var _Task$fromFunction, invoke2, cancel2, produced, _produced$just$right, invoke3, cancel3;
|
|
1814
|
-
|
|
1815
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1816
|
-
while (1) {
|
|
1817
|
-
switch (_context.prev = _context.next) {
|
|
1818
|
-
case 0:
|
|
1819
|
-
_context.prev = 0;
|
|
1820
|
-
_Task$fromFunction = Task.fromFunction(function () {
|
|
1821
|
-
return op(result);
|
|
1822
|
-
}, globalCancel), invoke2 = _Task$fromFunction._invoke, cancel2 = _Task$fromFunction._cancel;
|
|
1823
|
-
globalCancel.cancel = cancel2;
|
|
1824
|
-
_context.next = 5;
|
|
1825
|
-
return invoke2;
|
|
1826
|
-
|
|
1827
|
-
case 5:
|
|
1828
|
-
produced = _context.sent;
|
|
1829
|
-
|
|
1830
|
-
if (!produced.isNothing()) {
|
|
1831
|
-
_context.next = 8;
|
|
1832
|
-
break;
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
return _context.abrupt("return", Maybe.nothing());
|
|
1836
|
-
|
|
1837
|
-
case 8:
|
|
1838
|
-
if (!produced.just.isLeft()) {
|
|
1839
|
-
_context.next = 10;
|
|
1840
|
-
break;
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
return _context.abrupt("return", Maybe.just(Either.left(produced.just.left)));
|
|
1844
|
-
|
|
1845
|
-
case 10:
|
|
1846
|
-
_produced$just$right = produced.just.right, invoke3 = _produced$just$right._invoke, cancel3 = _produced$just$right._cancel;
|
|
1847
|
-
globalCancel.cancel = cancel3;
|
|
1848
|
-
return _context.abrupt("return", invoke3);
|
|
1849
|
-
|
|
1850
|
-
case 15:
|
|
1851
|
-
_context.prev = 15;
|
|
1852
|
-
_context.t0 = _context["catch"](0);
|
|
1853
|
-
return _context.abrupt("return", Maybe.just(Either.left(_context.t0)));
|
|
1854
|
-
|
|
1855
|
-
case 18:
|
|
1856
|
-
case "end":
|
|
1857
|
-
return _context.stop();
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
}, _callee, null, [[0, 15]]);
|
|
1861
|
-
}));
|
|
1862
|
-
|
|
1863
|
-
return function (_x) {
|
|
1864
|
-
return _ref.apply(this, arguments);
|
|
1865
|
-
};
|
|
1866
|
-
}()), function (error) {
|
|
1867
|
-
return globalCancel.cancel(error);
|
|
1868
|
-
});
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
function chainTaskEither(_task, op) {
|
|
1872
|
-
return chainTaskMaybe(_task, function (maybe) {
|
|
1873
|
-
return maybe.map(op).orMap(Task.canceled).just;
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
function mapTaskMaybe(_task, op) {
|
|
1878
|
-
return chainTaskMaybe(_task, function (maybe) {
|
|
1879
|
-
return op(maybe).matchMap({
|
|
1880
|
-
just: function just(either) {
|
|
1881
|
-
return either.matchMap({
|
|
1882
|
-
right: Task.resolved,
|
|
1883
|
-
left: Task.rejected
|
|
1884
|
-
}).right;
|
|
1885
|
-
},
|
|
1886
|
-
nothing: Task.canceled
|
|
1887
|
-
}).just;
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
function mapTaskEither(_task, op) {
|
|
1892
|
-
return mapTaskMaybe(_task, function (maybe) {
|
|
1893
|
-
return maybe.map(op);
|
|
1894
|
-
});
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
function tapTaskMaybe(_task, op) {
|
|
1898
|
-
return mapTaskMaybe(_task, function (value) {
|
|
1899
|
-
op(value);
|
|
1900
|
-
return value;
|
|
1901
|
-
});
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
function tapTaskEither(_task, op) {
|
|
1905
|
-
return tapTaskMaybe(_task, function (maybe) {
|
|
1906
|
-
return maybe.tap(op);
|
|
1907
|
-
});
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
|
-
var TaskClass = /*#__PURE__*/function () {
|
|
1911
|
-
function TaskClass(_invoke, _cancel) {
|
|
1912
|
-
this._invoke = _invoke;
|
|
1913
|
-
this._cancel = _cancel;
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
var _proto = TaskClass.prototype;
|
|
1917
|
-
|
|
1918
|
-
_proto.tapCanceled = function tapCanceled(op) {
|
|
1919
|
-
return tapTaskMaybe(this, function (maybe) {
|
|
1920
|
-
return maybe.orTap(op);
|
|
1921
|
-
});
|
|
1922
|
-
};
|
|
1923
|
-
|
|
1924
|
-
_proto.tapRejected = function tapRejected(op) {
|
|
1925
|
-
return tapTaskEither(this, function (either) {
|
|
1926
|
-
return either.orTap(op);
|
|
1927
|
-
});
|
|
1928
|
-
};
|
|
1929
|
-
|
|
1930
|
-
_proto.tap = function tap(op) {
|
|
1931
|
-
return tapTaskEither(this, function (either) {
|
|
1932
|
-
return either.tap(op);
|
|
1933
|
-
});
|
|
1934
|
-
};
|
|
1935
|
-
|
|
1936
|
-
_proto.mapCanceled = function mapCanceled(op) {
|
|
1937
|
-
return mapTaskMaybe(this, function (maybe) {
|
|
1938
|
-
return maybe.orMap(function () {
|
|
1939
|
-
return Either.right(op());
|
|
1940
|
-
});
|
|
1941
|
-
});
|
|
1942
|
-
};
|
|
1943
|
-
|
|
1944
|
-
_proto.mapRejected = function mapRejected(op) {
|
|
1945
|
-
return mapTaskEither(this, function (either) {
|
|
1946
|
-
return either.orMap(op);
|
|
1947
|
-
});
|
|
1948
|
-
};
|
|
1949
|
-
|
|
1950
|
-
_proto.map = function map(op) {
|
|
1951
|
-
return mapTaskEither(this, function (either) {
|
|
1952
|
-
return either.map(op);
|
|
1953
|
-
});
|
|
1954
|
-
};
|
|
1955
|
-
|
|
1956
|
-
_proto.chainCanceled = function chainCanceled(op) {
|
|
1957
|
-
var mapEither = function mapEither(either) {
|
|
1958
|
-
return either.map(Task.resolved).orMap(Task.rejected).right;
|
|
1959
|
-
};
|
|
1960
|
-
|
|
1961
|
-
return chainTaskMaybe(this, function (maybe) {
|
|
1962
|
-
return maybe.map(mapEither).orMap(op).just;
|
|
1963
|
-
});
|
|
1964
|
-
};
|
|
1965
|
-
|
|
1966
|
-
_proto.chainRejected = function chainRejected(op) {
|
|
1967
|
-
return chainTaskEither(this, function (either) {
|
|
1968
|
-
return either.map(Task.resolved).orMap(op).right;
|
|
1969
|
-
});
|
|
1970
|
-
};
|
|
1971
|
-
|
|
1972
|
-
_proto.chain = function chain(op) {
|
|
1973
|
-
return chainTaskEither(this, function (either) {
|
|
1974
|
-
return either.map(op).orMap(Task.rejected).right;
|
|
1975
|
-
});
|
|
1976
|
-
};
|
|
1977
|
-
|
|
1978
|
-
_proto.resolve = function resolve() {
|
|
1979
|
-
return this._invoke;
|
|
1980
|
-
};
|
|
1981
|
-
|
|
1982
|
-
_proto.cancel = function cancel() {
|
|
1983
|
-
return this._cancel(Maybe.nothing());
|
|
1984
|
-
};
|
|
1985
|
-
|
|
1986
|
-
_proto.reject = function reject(error) {
|
|
1987
|
-
return this._cancel(Maybe.just(error));
|
|
1988
|
-
};
|
|
1989
|
-
|
|
1990
|
-
_proto.generator = function generator() {
|
|
1991
|
-
return /*#__PURE__*/runtime_1.mark(function _callee2(task) {
|
|
1992
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1993
|
-
while (1) {
|
|
1994
|
-
switch (_context2.prev = _context2.next) {
|
|
1995
|
-
case 0:
|
|
1996
|
-
_context2.next = 2;
|
|
1997
|
-
return task;
|
|
1998
|
-
|
|
1999
|
-
case 2:
|
|
2000
|
-
return _context2.abrupt("return", _context2.sent);
|
|
2001
|
-
|
|
2002
|
-
case 3:
|
|
2003
|
-
case "end":
|
|
2004
|
-
return _context2.stop();
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
}, _callee2);
|
|
2008
|
-
})(this);
|
|
2009
|
-
};
|
|
2010
|
-
|
|
2011
|
-
_proto.matchTap = function matchTap(op) {
|
|
2012
|
-
return tapTaskMaybe(this, function (maybe) {
|
|
2013
|
-
return maybe.matchTap({
|
|
2014
|
-
just: function just(either) {
|
|
2015
|
-
return either.matchTap({
|
|
2016
|
-
right: op.resolved,
|
|
2017
|
-
left: op.rejected
|
|
2018
|
-
});
|
|
2019
|
-
},
|
|
2020
|
-
nothing: op.canceled
|
|
2021
|
-
});
|
|
2022
|
-
});
|
|
2023
|
-
};
|
|
2024
|
-
|
|
2025
|
-
_proto.matchMap = function matchMap(op) {
|
|
2026
|
-
return mapTaskMaybe(this, function (maybe) {
|
|
2027
|
-
return maybe.matchMap({
|
|
2028
|
-
just: function just(either) {
|
|
2029
|
-
return either.matchMap({
|
|
2030
|
-
right: op.resolved,
|
|
2031
|
-
left: op.rejected
|
|
2032
|
-
});
|
|
2033
|
-
},
|
|
2034
|
-
nothing: function nothing() {
|
|
2035
|
-
return Either.right(op.canceled());
|
|
2036
|
-
}
|
|
2037
|
-
});
|
|
2038
|
-
});
|
|
2039
|
-
};
|
|
2040
|
-
|
|
2041
|
-
_proto.matchChain = function matchChain(op) {
|
|
2042
|
-
return chainTaskMaybe(this, function (maybe) {
|
|
2043
|
-
return maybe.matchMap({
|
|
2044
|
-
just: function just(either) {
|
|
2045
|
-
return either.matchMap({
|
|
2046
|
-
right: op.resolved,
|
|
2047
|
-
left: op.rejected
|
|
2048
|
-
}).right;
|
|
2049
|
-
},
|
|
2050
|
-
nothing: op.canceled
|
|
2051
|
-
}).just;
|
|
2052
|
-
});
|
|
2053
|
-
};
|
|
2054
|
-
|
|
2055
|
-
return TaskClass;
|
|
2056
|
-
}();
|
|
2057
|
-
|
|
2058
|
-
export { Either, Just, Left, Maybe, Right, Task };
|
|
1
|
+
var t,r;!function(t){t.just=function(t){return t.just}}(t||(t={})),function(t){t.just=function(t){return new e(t)},t.nothing=function(){return n},t.fromOptional=function(r){return void 0!==r?t.just(r):t.nothing()},t.fromNullable=function(r){return t.fromOptional(r).chain(r=>null!==r?t.just(r):t.nothing())},t.isJust=function(t){return t.isJust()},t.isNothing=function(t){return t.isNothing()},t.everyJust=function(r){return r.every(t.isJust)},t.someJust=function(r){return r.some(t.isJust)},t.everyNothing=function(r){return r.every(t.isNothing)},t.someNothing=function(r){return r.some(t.isNothing)}}(r||(r={}));class e{constructor(t){this.just=void 0,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)}}const n=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)}};var i,u,c,o;!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 s(t)},t.left=function(t){return new a(t)},t.fromOptional=function(r,e){return void 0!==r?t.right(r):t.left(e)},t.fromNullable=function(r,e){return t.fromOptional(r,e).chain(n=>null!==n?t.right(r):t.left(e))},t.isRight=function(t){return t.isRight()},t.isLeft=function(t){return t.isLeft()},t.everyRight=function(r){return r.every(t.isRight)},t.someRight=function(r){return r.some(t.isRight)},t.everyLeft=function(r){return r.every(t.isLeft)},t.someLeft=function(r){return r.some(t.isLeft)}}(c||(c={}));class s{constructor(t){this.right=void 0,this.right=t}tap(t){return t(this.right),this}orTap(){return this}map(t){return c.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)}}class a{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 c.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)}}!function(e){function n(t,n){let i;const[u,o]=h();return e.create(new Promise(e=>{o(e),i=t(t=>u(r.just(c.right(t))),t=>u(r.just(c.left(t))))}),t=>{u(t.map(c.left)),n(i)})}e.create=function(t,r){return new d(t,r)},e.resolved=function(t){return e.create(Promise.resolve(r.just(c.right(t))),()=>{})},e.rejected=function(t){return e.create(Promise.resolve(r.just(c.left(t))),()=>{})},e.canceled=function(){return e.create(Promise.resolve(r.nothing()),()=>{})},e.fromPromise=function(t){const[n,i]=h();return e.create(new Promise(e=>{i(e),t.then(c.right,c.left).then(r.just).then(n)}),t=>n(t.map(c.left)))},e.fromFunction=function(t,n){const[i,u]=h(),o=t=>i(t.map(c.left));return n.cancel=o,e.create(new Promise(e=>{u(e);try{i(r.just(c.right(t())))}catch(t){i(r.just(c.left(t)))}}),o)},e.promiseGenerator=function(t){return e.fromPromise(t).generator()},e.lift=function(t){return function(){return e.fromPromise(t(...[].slice.call(arguments)))}},e.generate=function(t){const r=t(),n=t=>t.done?e.resolved(t.value):t.value.matchChain({resolved:t=>n(r.next(t)),rejected:t=>n(r.throw(t)),canceled:e.canceled});return e.resolved(void 0).chain(()=>n(r.next()))},e.timeout=function(t){return n(r=>setTimeout(()=>r(),t),clearTimeout)},e.fromCallback=n,e.sequence=function(t){return Array.from(t).reduce((t,r)=>t.chain(t=>r().map(r=>t.concat(r))),e.resolved([]))},e.all=function(n){const[i,u]=h(),o=Array.from(n),s=t=>o.forEach(r=>r._cancel(t)),a=o.map(r.nothing),f=t=>{i(t.map(c.left)),s(t)};return e.create(new Promise(e=>{if(u(e),o.length<1)return i(r.just(c.right([])));o.map((e,n)=>e.matchTap({resolved:e=>((e,n)=>{a[n]=r.just(e),r.everyJust(a)&&i(r.just(c.right(a.map(t.just))))})(e,n),rejected:t=>f(r.just(t)),canceled:()=>f(r.nothing())}))}),s)},e.any=function(n){const[i,u]=h(),o=Array.from(n),s=t=>o.forEach(r=>r._cancel(t)),a=o.map(r.nothing),f=t=>{i(t.map(c.right)),s(r.nothing())};return e.create(new Promise(e=>{if(u(e),o.length<1)return i(r.nothing());o.map((e,n)=>e.matchTap({resolved:t=>f(r.just(t)),rejected:e=>((e,n)=>{a[n]=r.just(e),r.everyJust(a)&&i(r.just(c.left(a.map(t.just))))})(e,n),canceled:()=>f(r.nothing())}))}),s)},e.limit=function(t,r){return e.any([t,r.chain(e.canceled)]).chainRejected(t=>e.rejected(t[0]))},e.repeat=function(t){const r=()=>t().chainRejected(r);return r()}}(o||(o={}));const h=()=>{const t=()=>{};let r=t;return[e=>{const n=r;r=t,n(e)},t=>{r=t}]};function f(t,e){const n={cancel:t._cancel};return o.create(t._invoke.then(function(t){try{return Promise.resolve(function(t,r){try{var e=t()}catch(t){return r(t)}return e&&e.then?e.then(void 0,r):e}(function(){const{_invoke:i,_cancel:u}=o.fromFunction(()=>e(t),n);return n.cancel=u,Promise.resolve(i).then(function(t){if(t.isNothing())return r.nothing();if(t.just.isLeft())return r.just(c.left(t.just.left));const{_invoke:e,_cancel:i}=t.just.right;return n.cancel=i,e})},function(t){return r.just(c.left(t))}))}catch(t){return Promise.reject(t)}}),t=>n.cancel(t))}function l(t,r){return f(t,t=>t.map(r).orMap(o.canceled).just)}function m(t,r){return f(t,t=>r(t).matchMap({just:t=>t.matchMap({right:o.resolved,left:o.rejected}).right,nothing:o.canceled}).just)}function p(t,r){return m(t,t=>t.map(r))}function g(t,r){return m(t,t=>(r(t),t))}function j(t,r){return g(t,t=>t.tap(r))}class d{constructor(t,r){this._invoke=void 0,this._cancel=void 0,this._invoke=t,this._cancel=r}tapCanceled(t){return g(this,r=>r.orTap(t))}tapRejected(t){return j(this,r=>r.orTap(t))}tap(t){return j(this,r=>r.tap(t))}mapCanceled(t){return m(this,r=>r.orMap(()=>c.right(t())))}mapRejected(t){return p(this,r=>r.orMap(t))}map(t){return p(this,r=>r.map(t))}chainCanceled(t){const r=t=>t.map(o.resolved).orMap(o.rejected).right;return f(this,e=>e.map(r).orMap(t).just)}chainRejected(t){return l(this,r=>r.map(o.resolved).orMap(t).right)}chain(t){return l(this,r=>r.map(t).orMap(o.rejected).right)}resolve(){return this._invoke}cancel(){return this._cancel(r.nothing())}reject(t){return this._cancel(r.just(t))}generator(){/*#__PURE__*/return regeneratorRuntime.mark(function t(r){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r;case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t)})(this)}matchTap(t){return g(this,r=>r.matchTap({just:r=>r.matchTap({right:t.resolved,left:t.rejected}),nothing:t.canceled}))}matchMap(t){return m(this,r=>r.matchMap({just:r=>r.matchMap({right:t.resolved,left:t.rejected}),nothing:()=>c.right(t.canceled())}))}matchChain(t){return f(this,r=>r.matchMap({just:r=>r.matchMap({right:t.resolved,left:t.rejected}).right,nothing:t.canceled}).just)}}export{c as Either,t as Just,u as Left,r as Maybe,i as Right,o as Task};
|
|
2059
2
|
//# sourceMappingURL=t-tasks.esm.js.map
|