scats 1.4.2 → 1.4.3

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.
Files changed (2) hide show
  1. package/dist/index.cjs +1927 -0
  2. package/package.json +8 -2
package/dist/index.cjs ADDED
@@ -0,0 +1,1927 @@
1
+ 'use strict';
2
+
3
+ class ArrayIterable {
4
+ [Symbol.iterator]() {
5
+ let i = 0;
6
+ const items = this.toArray;
7
+ return {
8
+ next() {
9
+ if (i < items.length) {
10
+ const value = items[i];
11
+ i = i + 1;
12
+ return {
13
+ value: value,
14
+ done: false
15
+ };
16
+ }
17
+ else {
18
+ return {
19
+ value: undefined,
20
+ done: true
21
+ };
22
+ }
23
+ }
24
+ };
25
+ }
26
+ foreach(job) {
27
+ this.toArray.forEach(x => job(x));
28
+ }
29
+ contains(item) {
30
+ return this.toArray.indexOf(item) >= 0;
31
+ }
32
+ forall(p) {
33
+ return this.toArray.every(i => p(i));
34
+ }
35
+ exists(p) {
36
+ return this.toArray.find(i => p(i)) !== undefined;
37
+ }
38
+ find(p) {
39
+ return option(this.toArray.find(i => p(i)));
40
+ }
41
+ count(p) {
42
+ let res = 0;
43
+ this.toArray.forEach(i => {
44
+ if (p(i)) {
45
+ res++;
46
+ }
47
+ });
48
+ return res;
49
+ }
50
+ get isEmpty() {
51
+ return this.size <= 0;
52
+ }
53
+ get nonEmpty() {
54
+ return !this.isEmpty;
55
+ }
56
+ get size() {
57
+ return this.toArray.length;
58
+ }
59
+ reduce(op) {
60
+ return this.reduceLeft(op);
61
+ }
62
+ reduceOption(op) {
63
+ return this.reduceLeftOption(op);
64
+ }
65
+ get headOption() {
66
+ return this.isEmpty ? none : some(this.head);
67
+ }
68
+ get head() {
69
+ if (this.isEmpty) {
70
+ throw new Error('head on empty collection');
71
+ }
72
+ else {
73
+ return this.toArray[0];
74
+ }
75
+ }
76
+ get lastOption() {
77
+ return this.isEmpty ? none : some(this.last);
78
+ }
79
+ get last() {
80
+ if (this.isEmpty) {
81
+ throw new Error('empty.last');
82
+ }
83
+ else {
84
+ return this.toArray[this.size - 1];
85
+ }
86
+ }
87
+ reduceLeft(op) {
88
+ if (this.isEmpty) {
89
+ throw new Error('empty.reduceLeft');
90
+ }
91
+ const array = this.toArray;
92
+ let acc = array[0];
93
+ if (array.length > 1) {
94
+ for (let i = 1; i < array.length; i++) {
95
+ acc = op(acc, array[i]);
96
+ }
97
+ }
98
+ return acc;
99
+ }
100
+ reduceLeftOption(op) {
101
+ return this.isEmpty ? none : some(this.reduceLeft(op));
102
+ }
103
+ foldRight(initial) {
104
+ return (op) => {
105
+ return new Collection(this.toArray)
106
+ .reverse
107
+ .foldLeft(initial)((a, n) => op(n, a));
108
+ };
109
+ }
110
+ reduceRight(op) {
111
+ if (this.isEmpty) {
112
+ throw new Error('empty.reduceRight');
113
+ }
114
+ let acc = this.last;
115
+ const array = this.toArray.reverse();
116
+ if (array.length > 1) {
117
+ for (let i = 1; i < array.length; i++) {
118
+ acc = op(acc, array[i]);
119
+ }
120
+ }
121
+ return acc;
122
+ }
123
+ reduceRightOption(op) {
124
+ return this.isEmpty ? none : some(this.reduceRight(op));
125
+ }
126
+ foldLeft(initial) {
127
+ return (op) => {
128
+ return this.toArray.reduce((a, n) => op(a, n), initial);
129
+ };
130
+ }
131
+ fold(initial) {
132
+ return this.foldLeft(initial);
133
+ }
134
+ groupBy(field) {
135
+ return this.foldLeft(HashMap$2.empty)((acc, next) => {
136
+ const key = field(next);
137
+ const existing = acc.get(key).getOrElseValue(Collection.empty);
138
+ return acc.set(key, new Collection(existing.toArray.concat(next)));
139
+ });
140
+ }
141
+ minBy(toNumber) {
142
+ if (this.isEmpty) {
143
+ throw new Error('empty.minBy');
144
+ }
145
+ else {
146
+ let res = this.head;
147
+ let min = toNumber(res);
148
+ this.toArray.forEach(i => {
149
+ const next = toNumber(i);
150
+ if (next < min) {
151
+ res = i;
152
+ min = next;
153
+ }
154
+ });
155
+ return res;
156
+ }
157
+ }
158
+ minByOption(toNumber) {
159
+ return this.isEmpty ? none : some(this.minBy(toNumber));
160
+ }
161
+ maxBy(toNumber) {
162
+ if (this.isEmpty) {
163
+ throw new Error('empty.maxBy');
164
+ }
165
+ else {
166
+ let res = this.head;
167
+ let max = toNumber(res);
168
+ this.toArray.forEach(i => {
169
+ const next = toNumber(i);
170
+ if (next > max) {
171
+ res = i;
172
+ max = next;
173
+ }
174
+ });
175
+ return res;
176
+ }
177
+ }
178
+ maxByOption(toNumber) {
179
+ return this.isEmpty ? none : some(this.maxBy(toNumber));
180
+ }
181
+ partition(p) {
182
+ const array = this.toArray;
183
+ const first = array.filter(i => p(i));
184
+ const second = array.filter(i => !p(i));
185
+ return [this.fromArray(first), this.fromArray(second)];
186
+ }
187
+ take(n) {
188
+ const items = this.toArray;
189
+ return items.length > n ? this.fromArray(items.slice(0, n)) : this;
190
+ }
191
+ takeRight(n) {
192
+ const array = this.toArray;
193
+ return array.length > n ? this.fromArray(array.slice(array.length - n, array.length)) : this;
194
+ }
195
+ takeWhile(p) {
196
+ const array = this.toArray;
197
+ let res = true;
198
+ let i = 0;
199
+ for (; res && i < array.length; i++) {
200
+ res = p(array[i]);
201
+ }
202
+ if (res) {
203
+ return this;
204
+ }
205
+ else {
206
+ return this.take(i - 1);
207
+ }
208
+ }
209
+ drop(n) {
210
+ const array = this.toArray;
211
+ if (n >= array.length) {
212
+ return this.fromArray([]);
213
+ }
214
+ else if (n === 0) {
215
+ return this;
216
+ }
217
+ else {
218
+ return this.fromArray(array.slice(n, array.length));
219
+ }
220
+ }
221
+ dropRight(n) {
222
+ const array = this.toArray;
223
+ if (n >= array.length) {
224
+ return this.fromArray([]);
225
+ }
226
+ else if (n === 0) {
227
+ return this;
228
+ }
229
+ else {
230
+ return this.fromArray(array.slice(0, array.length - n));
231
+ }
232
+ }
233
+ dropWhile(p) {
234
+ const array = this.toArray;
235
+ let res = true;
236
+ let i = 0;
237
+ for (; res && i < array.length; i++) {
238
+ res = p(array[i]);
239
+ }
240
+ if (res) {
241
+ return this.fromArray([]);
242
+ }
243
+ else {
244
+ return this.drop(i - 1);
245
+ }
246
+ }
247
+ sliding(length, step = 1) {
248
+ if (this.isEmpty) {
249
+ return Collection.empty;
250
+ }
251
+ else {
252
+ const itemsSize = this.size;
253
+ if (itemsSize <= length) {
254
+ return Collection.of(this);
255
+ }
256
+ else {
257
+ const result = [];
258
+ let left = 0;
259
+ let done = false;
260
+ let right = length;
261
+ const items = this.toArray;
262
+ while (!done) {
263
+ done = right >= itemsSize;
264
+ result.push(this.fromArray(items.slice(left, right)));
265
+ left += step;
266
+ right = left + length;
267
+ }
268
+ return new Collection(result);
269
+ }
270
+ }
271
+ }
272
+ grouped(length) {
273
+ return this.sliding(length, length);
274
+ }
275
+ mkString(separator = '') {
276
+ return this.toArray.join(separator);
277
+ }
278
+ sum(elementToNum) {
279
+ if (this.isEmpty) {
280
+ return 0;
281
+ }
282
+ else {
283
+ return this.toArray.reduce((acc, next) => acc + elementToNum(next), 0);
284
+ }
285
+ }
286
+ filter(p) {
287
+ return this.fromArray(this.toArray.filter(i => p(i)));
288
+ }
289
+ filterNot(p) {
290
+ return this.fromArray(this.toArray.filter(i => !p(i)));
291
+ }
292
+ splitAt(n) {
293
+ return [this.take(n), this.drop(n)];
294
+ }
295
+ span(p) {
296
+ return [this.takeWhile(p), this.dropWhile(p)];
297
+ }
298
+ get init() {
299
+ if (this.isEmpty)
300
+ throw new Error('empty.init');
301
+ return this.dropRight(1);
302
+ }
303
+ get tail() {
304
+ if (this.isEmpty)
305
+ throw new Error('empty.tail');
306
+ return this.drop(1);
307
+ }
308
+ groupMap(key) {
309
+ return (value) => {
310
+ return this.foldLeft(HashMap$2.empty)((acc, next) => {
311
+ const nextKey = key(next);
312
+ const existingColl = acc.getOrElse(nextKey, () => Collection.empty);
313
+ const updatedColl = existingColl.appended(value(next));
314
+ return acc.updated(nextKey, updatedColl);
315
+ });
316
+ };
317
+ }
318
+ groupMapReduce(key) {
319
+ return (value) => {
320
+ return (reduce) => {
321
+ return this.foldLeft(HashMap$2.empty)((acc, next) => {
322
+ const nextKey = key(next);
323
+ const nextValue = value(next);
324
+ return acc.updated(nextKey, acc.get(nextKey).map(e => reduce(e, nextValue)).getOrElseValue(nextValue));
325
+ });
326
+ };
327
+ };
328
+ }
329
+ scan(z) {
330
+ return this.scanLeft(z);
331
+ }
332
+ scanLeft(z) {
333
+ return (op) => {
334
+ const res = [z];
335
+ let acc = z;
336
+ this.toArray.forEach(i => {
337
+ acc = op(acc, i);
338
+ res.push(acc);
339
+ });
340
+ return this.fromArray(res);
341
+ };
342
+ }
343
+ scanRight(z) {
344
+ return (op) => {
345
+ const res = [z];
346
+ let acc = z;
347
+ this.toArray.reverse().forEach(i => {
348
+ acc = op(acc, i);
349
+ res.push(acc);
350
+ });
351
+ return this.fromArray(res.reverse());
352
+ };
353
+ }
354
+ get zipWithIndex() {
355
+ const res = [];
356
+ const array = this.toArray;
357
+ for (let i = 0; i < array.length; i++) {
358
+ res.push([array[i], i]);
359
+ }
360
+ return new Collection(res);
361
+ }
362
+ get tails() {
363
+ const array = this.toArray;
364
+ const res = [];
365
+ for (let i = 0; i <= array.length; i++) {
366
+ res.push(this.takeRight(array.length - i));
367
+ }
368
+ return new Collection(res);
369
+ }
370
+ get inits() {
371
+ const array = this.toArray;
372
+ const res = [];
373
+ for (let i = 0; i <= array.length; i++) {
374
+ res.push(this.take(array.length - i));
375
+ }
376
+ return new Collection(res);
377
+ }
378
+ }
379
+
380
+ class ArrayBackedCollection extends ArrayIterable {
381
+ checkWithinBounds(lo, hi) {
382
+ if (lo < 0)
383
+ throw new Error(`$lo is out of bounds (min 0, max ${this.items.length - 1})`);
384
+ if (hi > this.size)
385
+ throw new Error(`$lo is out of bounds (min 0, max ${this.items.length - 1})`);
386
+ }
387
+ get reverse() {
388
+ return this.fromArray(this.items.reverse());
389
+ }
390
+ get toArray() {
391
+ return this.items;
392
+ }
393
+ get(index) {
394
+ this.checkWithinBounds(index, index + 1);
395
+ return this.items[index];
396
+ }
397
+ get toSet() {
398
+ return HashSet$1.of(...this.items);
399
+ }
400
+ indexOf(item) {
401
+ return this.items.indexOf(item);
402
+ }
403
+ get distinct() {
404
+ return this.fromArray(Array.from(new Set(this.items)));
405
+ }
406
+ distinctBy(key) {
407
+ const keys = new Set();
408
+ const res = [];
409
+ this.foreach(item => {
410
+ const currentKey = key(item);
411
+ if (!keys.has(currentKey)) {
412
+ keys.add(currentKey);
413
+ res.push(item);
414
+ }
415
+ });
416
+ return this.fromArray(res);
417
+ }
418
+ appended(item) {
419
+ return this.fromArray(this.items.concat([item]));
420
+ }
421
+ appendedAll(other) {
422
+ return this.fromArray(this.items.concat(...other));
423
+ }
424
+ prepended(item) {
425
+ return this.fromArray([item].concat(this.items));
426
+ }
427
+ prependedAll(other) {
428
+ return this.fromArray(Array.from(other).concat(this.items));
429
+ }
430
+ concat(other) {
431
+ return this.appendedAll(other);
432
+ }
433
+ slice(from, until) {
434
+ return this.fromArray(this.items.slice(from, until));
435
+ }
436
+ sort(param) {
437
+ return this.fromArray(this.items.slice(0).sort(param));
438
+ }
439
+ sortBy(fieldToNumber) {
440
+ return this.sort(((a, b) => fieldToNumber(a) - fieldToNumber(b)));
441
+ }
442
+ get length() {
443
+ return this.size;
444
+ }
445
+ }
446
+ class Collection extends ArrayBackedCollection {
447
+ items;
448
+ constructor(items) {
449
+ super();
450
+ this.items = items;
451
+ }
452
+ static empty = new Collection([]);
453
+ fromArray(array) {
454
+ if (!array || array.length <= 0) {
455
+ return Nil;
456
+ }
457
+ else {
458
+ return new Collection(array);
459
+ }
460
+ }
461
+ static of(...items) {
462
+ return new Collection(items);
463
+ }
464
+ static from(elements) {
465
+ return new Collection(Array.from(elements));
466
+ }
467
+ static fill(len) {
468
+ return function (elem) {
469
+ const res = new Array(len);
470
+ for (let i = 0; i < len; i++) {
471
+ res[i] = elem(i);
472
+ }
473
+ return new Collection(res);
474
+ };
475
+ }
476
+ map(f) {
477
+ return new Collection(this.items.map(i => f(i)));
478
+ }
479
+ flatMap(f) {
480
+ let res = [];
481
+ this.items.forEach(i => {
482
+ res = res.concat(f(i).items);
483
+ });
484
+ return new Collection(res);
485
+ }
486
+ flatMapOption(f) {
487
+ const res = [];
488
+ this.items.forEach(i => {
489
+ f(i).foreach(v => {
490
+ res.push(v);
491
+ });
492
+ });
493
+ return new Collection(res);
494
+ }
495
+ async mapPromise(f) {
496
+ const res = [];
497
+ for (let i = 0; i < this.items.length; i++) {
498
+ res.push(await f(this.items[i]));
499
+ }
500
+ return new Collection(res);
501
+ }
502
+ async mapPromiseAll(f) {
503
+ return new Collection(await Promise.all(this.items.map(i => f(i))));
504
+ }
505
+ async flatMapPromise(f) {
506
+ let res = [];
507
+ for (let i = 0; i < this.items.length; i++) {
508
+ const item = this.items[i];
509
+ res = res.concat((await f(item)).items);
510
+ }
511
+ return new Collection(res);
512
+ }
513
+ async flatMapPromiseAll(f) {
514
+ return (await this.mapPromiseAll(f)).flatten();
515
+ }
516
+ flatten() {
517
+ const res = [];
518
+ this.items.forEach(i => {
519
+ if (i instanceof Collection) {
520
+ res.push(...i.items);
521
+ }
522
+ else {
523
+ res.push(i);
524
+ }
525
+ });
526
+ return new Collection(res);
527
+ }
528
+ get toBuffer() {
529
+ return new ArrayBuffer(this.items);
530
+ }
531
+ toMap(mapper) {
532
+ return HashMap$2.of(...this.map(mapper).toArray);
533
+ }
534
+ zip(that) {
535
+ const res = [];
536
+ for (let i = 0; i < Math.min(this.size, that.size); i++) {
537
+ res.push([this.items[i], that.items[i]]);
538
+ }
539
+ return new Collection(res);
540
+ }
541
+ zipAll(that, thisElem, thatElem) {
542
+ const res = [];
543
+ for (let i = 0; i < Math.max(this.size, that.size); i++) {
544
+ res.push([
545
+ i < this.items.length ? this.items[i] : thisElem,
546
+ i < that.items.length ? that.items[i] : thatElem
547
+ ]);
548
+ }
549
+ return new Collection(res);
550
+ }
551
+ }
552
+ const Nil = Collection.empty;
553
+ class ArrayBuffer extends ArrayBackedCollection {
554
+ items;
555
+ static get empty() {
556
+ return new ArrayBuffer([]);
557
+ }
558
+ constructor(items = []) {
559
+ super();
560
+ this.items = items;
561
+ }
562
+ static of(...elements) {
563
+ return new ArrayBuffer(elements);
564
+ }
565
+ static from(elements) {
566
+ return new ArrayBuffer(Array.from(elements));
567
+ }
568
+ static fill(len) {
569
+ return function (elem) {
570
+ const res = new Array(len);
571
+ for (let i = 0; i < len; i++) {
572
+ res[i] = elem(i);
573
+ }
574
+ return new ArrayBuffer(res);
575
+ };
576
+ }
577
+ fromArray(array) {
578
+ if (!array || array.length <= 0) {
579
+ return new ArrayBuffer([]);
580
+ }
581
+ else {
582
+ return new ArrayBuffer(array);
583
+ }
584
+ }
585
+ normalized(n) {
586
+ return Math.min(Math.max(n, 0), this.length);
587
+ }
588
+ update(index, element) {
589
+ this.checkWithinBounds(index, index + 1);
590
+ this.items[index] = element;
591
+ }
592
+ set(index, element) {
593
+ this.update(index, element);
594
+ }
595
+ clear() {
596
+ this.items.length = 0;
597
+ }
598
+ append(element) {
599
+ this.items.push(element);
600
+ return this;
601
+ }
602
+ appendAll(elements) {
603
+ this.items.push(...elements);
604
+ return this;
605
+ }
606
+ prepend(element) {
607
+ this.items.unshift(element);
608
+ return this;
609
+ }
610
+ prependAll(elements) {
611
+ this.items.unshift(...elements);
612
+ return this;
613
+ }
614
+ insert(idx, element) {
615
+ this.checkWithinBounds(idx, idx);
616
+ this.items.splice(idx, 0, element);
617
+ }
618
+ insertAll(idx, elements) {
619
+ this.checkWithinBounds(idx, idx);
620
+ this.items.splice(idx, 0, ...elements);
621
+ }
622
+ remove(index, count = 1) {
623
+ if (count > 0) {
624
+ this.checkWithinBounds(index, index + 1);
625
+ this.items.splice(index, count);
626
+ }
627
+ else if (count < 0) {
628
+ throw new Error('removing negative number of elements: ' + count);
629
+ }
630
+ }
631
+ subtractOne(element) {
632
+ const i = this.items.indexOf(element);
633
+ if (i != -1) {
634
+ this.remove(i);
635
+ }
636
+ return this;
637
+ }
638
+ subtractAll(elements) {
639
+ if (elements === this || elements === this.items) {
640
+ const buf = new ArrayBuffer(Array.from(elements));
641
+ buf.foreach(e => this.subtractOne(e));
642
+ }
643
+ else {
644
+ for (const element of elements) {
645
+ this.subtractOne(element);
646
+ }
647
+ }
648
+ return this;
649
+ }
650
+ sort(compareFn) {
651
+ this.items.sort(compareFn);
652
+ return this;
653
+ }
654
+ filterInPlace(p) {
655
+ let i = 0, j = 0;
656
+ while (i < this.size) {
657
+ if (p(this.items[i])) {
658
+ if (i != j) {
659
+ this.items[j] = this.items[i];
660
+ }
661
+ j += 1;
662
+ }
663
+ i += 1;
664
+ }
665
+ if (i == j) {
666
+ return this;
667
+ }
668
+ else {
669
+ return this.takeInPlace(j);
670
+ }
671
+ }
672
+ dropInPlace(n) {
673
+ this.remove(0, this.normalized(n));
674
+ return this;
675
+ }
676
+ dropRightInPlace(n) {
677
+ const norm = this.normalized(n);
678
+ this.remove(this.length - norm, norm);
679
+ return this;
680
+ }
681
+ takeInPlace(n) {
682
+ const norm = this.normalized(n);
683
+ this.remove(norm, this.length - norm);
684
+ return this;
685
+ }
686
+ takeRightInPlace(n) {
687
+ this.remove(0, this.length - this.normalized(n));
688
+ return this;
689
+ }
690
+ sliceInPlace(start, end) {
691
+ return this.takeInPlace(end).dropInPlace(start);
692
+ }
693
+ get toCollection() {
694
+ return new Collection(this.items.slice(0));
695
+ }
696
+ flatMap(f) {
697
+ let res = [];
698
+ this.items.forEach(i => {
699
+ res = res.concat(f(i).items);
700
+ });
701
+ return new ArrayBuffer(res);
702
+ }
703
+ flatMapOption(f) {
704
+ const res = [];
705
+ this.items.forEach(i => {
706
+ f(i).foreach(v => {
707
+ res.push(v);
708
+ });
709
+ });
710
+ return new ArrayBuffer(res);
711
+ }
712
+ async flatMapPromise(f) {
713
+ let res = [];
714
+ for (let i = 0; i < this.items.length; i++) {
715
+ const item = this.items[i];
716
+ res = res.concat((await f(item)).items);
717
+ }
718
+ return new ArrayBuffer(res);
719
+ }
720
+ map(f) {
721
+ return new ArrayBuffer(this.items.map(i => f(i)));
722
+ }
723
+ async mapPromise(f) {
724
+ const res = [];
725
+ for (let i = 0; i < this.items.length; i++) {
726
+ res.push(await f(this.items[i]));
727
+ }
728
+ return new ArrayBuffer(res);
729
+ }
730
+ async mapPromiseAll(f) {
731
+ return new ArrayBuffer(await Promise.all(this.items.map(i => f(i))));
732
+ }
733
+ async flatMapPromiseAll(f) {
734
+ return (await this.mapPromiseAll(f)).flatten();
735
+ }
736
+ flatten() {
737
+ const res = [];
738
+ this.items.forEach(i => {
739
+ if (i instanceof ArrayBuffer) {
740
+ res.push(...i.items);
741
+ }
742
+ else {
743
+ res.push(i);
744
+ }
745
+ });
746
+ return new ArrayBuffer(res);
747
+ }
748
+ toMap(mapper) {
749
+ return HashMap$2.of(...this.map(mapper).toArray);
750
+ }
751
+ }
752
+
753
+ class AbstractMap extends ArrayIterable {
754
+ map;
755
+ constructor(map) {
756
+ super();
757
+ this.map = map;
758
+ }
759
+ get size() {
760
+ return this.map.size;
761
+ }
762
+ get isEmpty() {
763
+ return this.map.size <= 0;
764
+ }
765
+ get(key) {
766
+ return option(this.map.get(key));
767
+ }
768
+ getOrElse(key, defaultValue) {
769
+ return this.get(key).getOrElse(defaultValue);
770
+ }
771
+ getOrElseValue(key, defaultValue) {
772
+ return this.get(key).getOrElseValue(defaultValue);
773
+ }
774
+ get keySet() {
775
+ return HashSet$1.of(...Array.from(this.map.keys()));
776
+ }
777
+ get keyIterator() {
778
+ return this.map.keys();
779
+ }
780
+ get keys() {
781
+ return new Collection(Array.from(this.map.keys()));
782
+ }
783
+ get values() {
784
+ return new Collection(Array.from(this.map.values()));
785
+ }
786
+ get valueIterator() {
787
+ return this.map.values();
788
+ }
789
+ get entries() {
790
+ return new Collection(Array.from(this.map.entries()));
791
+ }
792
+ get entriesIterator() {
793
+ return this.map.entries();
794
+ }
795
+ containsKey(key) {
796
+ return this.map.has(key);
797
+ }
798
+ get toCollection() {
799
+ return new Collection(Array.from(this.map.entries()));
800
+ }
801
+ get toMap() {
802
+ return this.map;
803
+ }
804
+ get toArray() {
805
+ return Array.from(this.map.entries());
806
+ }
807
+ }
808
+
809
+ let HashMap$2 = class HashMap extends AbstractMap {
810
+ map;
811
+ fromArray(array) {
812
+ return HashMap.of(...array);
813
+ }
814
+ constructor(map) {
815
+ super(map);
816
+ this.map = map;
817
+ }
818
+ static of(...values) {
819
+ return new HashMap(new Map(values));
820
+ }
821
+ static from(values) {
822
+ return HashMap.of(...Array.from(values));
823
+ }
824
+ static empty = new HashMap(new Map());
825
+ appendedAll(map) {
826
+ return this.concat(map);
827
+ }
828
+ appended(key, value) {
829
+ return this.set(key, value);
830
+ }
831
+ updated(key, value) {
832
+ return this.set(key, value);
833
+ }
834
+ removed(key) {
835
+ const next = new Map(this.map);
836
+ next.delete(key);
837
+ return new HashMap(next);
838
+ }
839
+ removedAll(keys) {
840
+ const next = new Map(this.map);
841
+ for (const key of keys) {
842
+ next.delete(key);
843
+ }
844
+ return new HashMap(next);
845
+ }
846
+ concat(map) {
847
+ const mergedMap = new Map([
848
+ ...this.entries.toArray,
849
+ ...map.entries.toArray
850
+ ]);
851
+ return new HashMap(mergedMap);
852
+ }
853
+ set(key, value) {
854
+ const next = new Map(this.map);
855
+ next.set(key, value);
856
+ return new HashMap(new Map(next));
857
+ }
858
+ updatedWith(key) {
859
+ const previousValue = this.get(key);
860
+ return (remappingFunction) => {
861
+ const nextValue = remappingFunction(previousValue);
862
+ if (previousValue.isEmpty && nextValue.isEmpty) {
863
+ return this;
864
+ }
865
+ else if (previousValue.isDefined && nextValue.isEmpty) {
866
+ return this.removed(key);
867
+ }
868
+ else {
869
+ return this.updated(key, nextValue.get);
870
+ }
871
+ };
872
+ }
873
+ get toMutable() {
874
+ return HashMap$1.of(...Array.from(this.map.entries()));
875
+ }
876
+ };
877
+
878
+ class AbstractSet extends ArrayIterable {
879
+ items;
880
+ constructor(items) {
881
+ super();
882
+ this.items = items;
883
+ }
884
+ contains(item) {
885
+ return this.items.has(item);
886
+ }
887
+ get toArray() {
888
+ return Array.from(this.items.keys());
889
+ }
890
+ get toCollection() {
891
+ return new Collection(Array.from(this.items.keys()));
892
+ }
893
+ get toSet() {
894
+ return new Set(this.items);
895
+ }
896
+ get isEmpty() {
897
+ return this.items.size <= 0;
898
+ }
899
+ get size() {
900
+ return this.items.size;
901
+ }
902
+ get toBuffer() {
903
+ return new ArrayBuffer(Array.from(this.items.keys()));
904
+ }
905
+ }
906
+
907
+ let HashSet$2 = class HashSet extends AbstractSet {
908
+ constructor(items = new Set()) {
909
+ super(items);
910
+ }
911
+ static of(...items) {
912
+ return new HashSet(new Set(items));
913
+ }
914
+ static from(values) {
915
+ return HashSet.of(...Array.from(values));
916
+ }
917
+ fromArray(array) {
918
+ return HashSet.of(...array);
919
+ }
920
+ add(elem) {
921
+ const res = this.items.has(elem);
922
+ if (!res) {
923
+ this.items.add(elem);
924
+ return true;
925
+ }
926
+ else {
927
+ return !res;
928
+ }
929
+ }
930
+ addAll(xs) {
931
+ for (const x of xs) {
932
+ this.items.add(x);
933
+ }
934
+ return this;
935
+ }
936
+ subtractAll(xs) {
937
+ for (const x of xs) {
938
+ this.items.delete(x);
939
+ }
940
+ return this;
941
+ }
942
+ remove(elem) {
943
+ const res = this.items.has(elem);
944
+ if (res) {
945
+ this.items.delete(elem);
946
+ return true;
947
+ }
948
+ else {
949
+ return res;
950
+ }
951
+ }
952
+ filterInPlace(p) {
953
+ if (this.nonEmpty) {
954
+ const arr = this.toArray;
955
+ for (const t of arr) {
956
+ if (!p(t)) {
957
+ this.remove(t);
958
+ }
959
+ }
960
+ }
961
+ return this;
962
+ }
963
+ clear() {
964
+ this.items.clear();
965
+ }
966
+ addOne(elem) {
967
+ this.add(elem);
968
+ return this;
969
+ }
970
+ subtractOne(elem) {
971
+ this.remove(elem);
972
+ return this;
973
+ }
974
+ concat(that) {
975
+ const newSet = new Set([...this.items, ...that]);
976
+ return new HashSet(newSet);
977
+ }
978
+ intersect(that) {
979
+ return this.filter(x => that.contains(x));
980
+ }
981
+ union(that) {
982
+ return this.concat(that);
983
+ }
984
+ get toImmutable() {
985
+ return HashSet$1.of(...this.items);
986
+ }
987
+ };
988
+
989
+ let HashSet$1 = class HashSet extends AbstractSet {
990
+ constructor(items) {
991
+ super(items);
992
+ }
993
+ static empty = new HashSet(new Set());
994
+ static of(...items) {
995
+ return new HashSet(new Set(items));
996
+ }
997
+ static from(elements) {
998
+ return new HashSet(new Set(elements));
999
+ }
1000
+ fromArray(array) {
1001
+ return HashSet.of(...array);
1002
+ }
1003
+ toMap(mapper) {
1004
+ return HashMap$2.of(...this.map(mapper).toArray);
1005
+ }
1006
+ map(f) {
1007
+ return HashSet.of(...Array.from(this.items).map(i => f(i)));
1008
+ }
1009
+ flatMap(f) {
1010
+ const res = new Set();
1011
+ this.items.forEach(i => f(i).foreach(e => res.add(e)));
1012
+ return new HashSet(res);
1013
+ }
1014
+ concat(that) {
1015
+ return this.appendedAll(that);
1016
+ }
1017
+ union(other) {
1018
+ return this.concat(other);
1019
+ }
1020
+ appended(item) {
1021
+ return this.fromArray(this.toArray.concat([item]));
1022
+ }
1023
+ appendedAll(other) {
1024
+ const res = Array.from(this.items);
1025
+ res.push(...Array.from(other));
1026
+ return this.fromArray(res);
1027
+ }
1028
+ removed(item) {
1029
+ const res = new Set(Array.from(this.items));
1030
+ res.delete(item);
1031
+ return new HashSet(res);
1032
+ }
1033
+ removedAll(other) {
1034
+ const res = new Set(Array.from(this.items));
1035
+ for (const element of other) {
1036
+ res.delete(element);
1037
+ }
1038
+ return new HashSet(res);
1039
+ }
1040
+ intersect(other) {
1041
+ return this.filter(x => other.contains(x));
1042
+ }
1043
+ get toMutable() {
1044
+ return HashSet$2.of(...this.items);
1045
+ }
1046
+ };
1047
+
1048
+ class Option extends ArrayIterable {
1049
+ static when(cond) {
1050
+ return a => {
1051
+ if (cond) {
1052
+ return some(a());
1053
+ }
1054
+ else {
1055
+ return none;
1056
+ }
1057
+ };
1058
+ }
1059
+ static useless(cond) {
1060
+ return Option.when(!cond);
1061
+ }
1062
+ fromArray(array) {
1063
+ if (array.length <= 0) {
1064
+ return none;
1065
+ }
1066
+ else {
1067
+ return some(array[0]);
1068
+ }
1069
+ }
1070
+ exists(p) {
1071
+ if (this.isEmpty) {
1072
+ return false;
1073
+ }
1074
+ else {
1075
+ return p(this.get);
1076
+ }
1077
+ }
1078
+ filter(p) {
1079
+ if (this.isEmpty) {
1080
+ return none;
1081
+ }
1082
+ else {
1083
+ return p(this.get) ? this : none;
1084
+ }
1085
+ }
1086
+ filterNot(p) {
1087
+ if (this.isEmpty) {
1088
+ return none;
1089
+ }
1090
+ else {
1091
+ return p(this.get) ? none : this;
1092
+ }
1093
+ }
1094
+ map(f) {
1095
+ return this.isEmpty ? none : some(f(this.get));
1096
+ }
1097
+ flatMap(p) {
1098
+ return this.isEmpty ? none : p(this.get);
1099
+ }
1100
+ async mapPromise(f) {
1101
+ if (this.isEmpty) {
1102
+ return Promise.resolve(none);
1103
+ }
1104
+ else {
1105
+ return option(await f(this.get));
1106
+ }
1107
+ }
1108
+ flatMapPromise(f) {
1109
+ if (this.isEmpty) {
1110
+ return Promise.resolve(none);
1111
+ }
1112
+ else {
1113
+ return f(this.get);
1114
+ }
1115
+ }
1116
+ foldValue(ifEmpty) {
1117
+ if (this.isEmpty) {
1118
+ return function () { return ifEmpty(); };
1119
+ }
1120
+ else {
1121
+ return (f) => { return f(this.get); };
1122
+ }
1123
+ }
1124
+ forall(p) {
1125
+ return this.isEmpty ? true : p(this.get);
1126
+ }
1127
+ foreach(f) {
1128
+ if (this.nonEmpty) {
1129
+ f(this.get);
1130
+ }
1131
+ }
1132
+ getOrElse(f) {
1133
+ return this.isEmpty ? f() : this.get;
1134
+ }
1135
+ getOrElseValue(other) {
1136
+ return this.isEmpty ? other : this.get;
1137
+ }
1138
+ getOrElseThrow(error) {
1139
+ if (this.isEmpty) {
1140
+ throw error();
1141
+ }
1142
+ else {
1143
+ return this.get;
1144
+ }
1145
+ }
1146
+ contains(x) {
1147
+ return this.isEmpty ? false : x === this.get;
1148
+ }
1149
+ get isDefined() {
1150
+ return !this.isEmpty;
1151
+ }
1152
+ orElse(alternative) {
1153
+ return this.isEmpty ? alternative() : this;
1154
+ }
1155
+ orElseValue(alternative) {
1156
+ return this.isEmpty ? alternative : this;
1157
+ }
1158
+ get orNull() {
1159
+ return this.isEmpty ? null : this.get;
1160
+ }
1161
+ get orUndefined() {
1162
+ return this.isEmpty ? undefined : this.get;
1163
+ }
1164
+ get toCollection() {
1165
+ return this.isEmpty ? Collection.empty : Collection.of(this.get);
1166
+ }
1167
+ toRight(left) {
1168
+ return this.isEmpty ? new Left(left()) : right(this.get);
1169
+ }
1170
+ toLeft(right) {
1171
+ return this.isEmpty ? new Right(right()) : left(this.get);
1172
+ }
1173
+ get toArray() {
1174
+ return this.isEmpty ? [] : [this.get];
1175
+ }
1176
+ get toSet() {
1177
+ return this.isEmpty ? HashSet$1.empty : HashSet$1.of(this.get);
1178
+ }
1179
+ match(matcher) {
1180
+ return this.isEmpty ? matcher.none() : matcher.some(this.get);
1181
+ }
1182
+ toMap(mapper) {
1183
+ return this.isEmpty ? HashMap$2.empty : HashMap$2.of(...this.map(mapper).toArray);
1184
+ }
1185
+ }
1186
+ class Some extends Option {
1187
+ value;
1188
+ constructor(value) {
1189
+ super();
1190
+ this.value = value;
1191
+ }
1192
+ get get() {
1193
+ return this.value;
1194
+ }
1195
+ get isEmpty() {
1196
+ return false;
1197
+ }
1198
+ }
1199
+ class None extends Option {
1200
+ get get() {
1201
+ throw new Error('No such element.');
1202
+ }
1203
+ get isEmpty() {
1204
+ return true;
1205
+ }
1206
+ }
1207
+ function option(value) {
1208
+ return value === null || typeof value === 'undefined' ? none : some(value);
1209
+ }
1210
+ function some(value) {
1211
+ return new Some(value);
1212
+ }
1213
+ const none = new None();
1214
+
1215
+ function identity(x) {
1216
+ return x;
1217
+ }
1218
+ function toErrorConversion(x) {
1219
+ if (x instanceof Error) {
1220
+ return x;
1221
+ }
1222
+ else {
1223
+ return new Error(`${x}`);
1224
+ }
1225
+ }
1226
+ class StepWithFilter {
1227
+ name;
1228
+ f;
1229
+ filter;
1230
+ constructor(name, f, filter) {
1231
+ this.name = name;
1232
+ this.f = f;
1233
+ this.filter = filter;
1234
+ }
1235
+ if(condition) {
1236
+ return new StepWithFilter(this.name, this.f, some(condition));
1237
+ }
1238
+ invokeStep(state) {
1239
+ const result = this.f(state);
1240
+ return this.filter.filter(() => 'filter' in result).map(filter => {
1241
+ return result.filter(x => {
1242
+ this.name.foreach(name => state[name] = x);
1243
+ return filter(state);
1244
+ });
1245
+ }).getOrElseValue(result);
1246
+ }
1247
+ }
1248
+ class TaskWithFilter {
1249
+ name;
1250
+ f;
1251
+ filter;
1252
+ constructor(name, f, filter) {
1253
+ this.name = name;
1254
+ this.f = f;
1255
+ this.filter = filter;
1256
+ }
1257
+ if(condition) {
1258
+ return new TaskWithFilter(this.name, this.f, some(condition));
1259
+ }
1260
+ async invokeStep(state) {
1261
+ const result = await this.f(state);
1262
+ return this.filter.filter(() => 'filter' in result).map(filter => {
1263
+ return result.filter(x => {
1264
+ this.name.foreach(name => state[name] = x);
1265
+ return filter(state);
1266
+ });
1267
+ }).getOrElseValue(result);
1268
+ }
1269
+ }
1270
+ function step(name, f) {
1271
+ return new StepWithFilter(some(name), f, none);
1272
+ }
1273
+ function task(name, f) {
1274
+ return new TaskWithFilter(some(name), f, none);
1275
+ }
1276
+ function forComprehension(...steps) {
1277
+ return {
1278
+ yield: function (final) {
1279
+ function processStep(stepIdx, acc) {
1280
+ const result = steps[stepIdx].invokeStep(acc);
1281
+ if (stepIdx < steps.length - 1) {
1282
+ return result.flatMap(x => {
1283
+ steps[stepIdx].name.foreach(name => acc[name] = x);
1284
+ return processStep(stepIdx + 1, acc);
1285
+ });
1286
+ }
1287
+ else {
1288
+ return result.map(x => {
1289
+ steps[stepIdx].name.foreach(name => acc[name] = x);
1290
+ return final(acc);
1291
+ });
1292
+ }
1293
+ }
1294
+ return processStep(0, {});
1295
+ }
1296
+ };
1297
+ }
1298
+ (function (forComprehension) {
1299
+ function promise(...steps) {
1300
+ return {
1301
+ yield: function (final) {
1302
+ async function processStep(stepIdx, acc) {
1303
+ const result = await steps[stepIdx].invokeStep(acc);
1304
+ if (stepIdx < steps.length - 1) {
1305
+ return await result.flatMapPromise(x => {
1306
+ steps[stepIdx].name.foreach(name => acc[name] = x);
1307
+ return processStep(stepIdx + 1, acc);
1308
+ });
1309
+ }
1310
+ else {
1311
+ return result.map(x => {
1312
+ steps[stepIdx].name.foreach(name => acc[name] = x);
1313
+ return final(acc);
1314
+ });
1315
+ }
1316
+ }
1317
+ return processStep(0, {});
1318
+ }
1319
+ };
1320
+ }
1321
+ forComprehension.promise = promise;
1322
+ })(forComprehension || (forComprehension = {}));
1323
+
1324
+ class TryLike {
1325
+ async mapPromise(f) {
1326
+ return this.match({
1327
+ success: r => Try.promise(() => f(r)),
1328
+ failure: () => Promise.resolve(this)
1329
+ });
1330
+ }
1331
+ flatMapPromise(f) {
1332
+ return this.match({
1333
+ success: r => f(r),
1334
+ failure: () => Promise.resolve(this)
1335
+ });
1336
+ }
1337
+ foreach(f) {
1338
+ if (this.isSuccess) {
1339
+ f(this.get);
1340
+ }
1341
+ }
1342
+ tapFailure(f) {
1343
+ return this.match({
1344
+ success: () => this,
1345
+ failure: e => {
1346
+ try {
1347
+ f(e);
1348
+ return this;
1349
+ }
1350
+ catch (ex) {
1351
+ return failure(ex);
1352
+ }
1353
+ }
1354
+ });
1355
+ }
1356
+ toEitherWithLeft(f) {
1357
+ return this.match({
1358
+ success: r => right(r),
1359
+ failure: e => left(f(e))
1360
+ });
1361
+ }
1362
+ }
1363
+ class Success extends TryLike {
1364
+ result;
1365
+ isSuccess = true;
1366
+ isFailure = false;
1367
+ constructor(result) {
1368
+ super();
1369
+ this.result = result;
1370
+ }
1371
+ get toOption() {
1372
+ return some(this.result);
1373
+ }
1374
+ get toEither() {
1375
+ return right(this.result);
1376
+ }
1377
+ map(f) {
1378
+ return success(f(this.result));
1379
+ }
1380
+ get get() {
1381
+ return this.result;
1382
+ }
1383
+ getOrElse(_) {
1384
+ return this.result;
1385
+ }
1386
+ getOrElseValue(_) {
1387
+ return this.result;
1388
+ }
1389
+ orElse(_) {
1390
+ return this;
1391
+ }
1392
+ match(matcher) {
1393
+ return matcher.success(this.result);
1394
+ }
1395
+ flatMap(f) {
1396
+ try {
1397
+ return f(this.result);
1398
+ }
1399
+ catch (e) {
1400
+ return failure(e);
1401
+ }
1402
+ }
1403
+ filter(p) {
1404
+ try {
1405
+ if (p(this.result)) {
1406
+ return this;
1407
+ }
1408
+ else {
1409
+ return failure(new Error('Predicate does not hold for ' + this.result));
1410
+ }
1411
+ }
1412
+ catch (e) {
1413
+ return failure(e);
1414
+ }
1415
+ }
1416
+ get failed() {
1417
+ return failure(new Error('Success.failed'));
1418
+ }
1419
+ fold(fa, fb) {
1420
+ try {
1421
+ return fb(this.result);
1422
+ }
1423
+ catch (e) {
1424
+ return fa(e);
1425
+ }
1426
+ }
1427
+ recover(_) {
1428
+ return this;
1429
+ }
1430
+ recoverWith(_) {
1431
+ return this;
1432
+ }
1433
+ transform(s, _) {
1434
+ return this.flatMap(s);
1435
+ }
1436
+ }
1437
+ class Failure extends TryLike {
1438
+ error;
1439
+ isSuccess = false;
1440
+ isFailure = true;
1441
+ constructor(error) {
1442
+ super();
1443
+ this.error = error;
1444
+ }
1445
+ get toOption() {
1446
+ return none;
1447
+ }
1448
+ get toEither() {
1449
+ return left(this.error);
1450
+ }
1451
+ map(_) {
1452
+ return this;
1453
+ }
1454
+ get get() {
1455
+ throw this.error;
1456
+ }
1457
+ getOrElse(value) {
1458
+ return value();
1459
+ }
1460
+ getOrElseValue(value) {
1461
+ return value;
1462
+ }
1463
+ orElse(value) {
1464
+ try {
1465
+ return value();
1466
+ }
1467
+ catch (e) {
1468
+ return failure(e);
1469
+ }
1470
+ }
1471
+ match(matcher) {
1472
+ return matcher.failure(this.error);
1473
+ }
1474
+ flatMap(_) {
1475
+ return this;
1476
+ }
1477
+ filter(_) {
1478
+ return this;
1479
+ }
1480
+ get failed() {
1481
+ return success(this.error);
1482
+ }
1483
+ fold(fa, _) {
1484
+ return fa(this.error);
1485
+ }
1486
+ recover(f) {
1487
+ try {
1488
+ return success(f(this.error));
1489
+ }
1490
+ catch (ex) {
1491
+ return failure(ex);
1492
+ }
1493
+ }
1494
+ recoverWith(f) {
1495
+ return this.transform(identity, f);
1496
+ }
1497
+ transform(s, f) {
1498
+ try {
1499
+ return f(this.error);
1500
+ }
1501
+ catch (ex) {
1502
+ return failure(ex);
1503
+ }
1504
+ }
1505
+ }
1506
+ function Try(block) {
1507
+ try {
1508
+ return new Success(block());
1509
+ }
1510
+ catch (e) {
1511
+ return new Failure(e);
1512
+ }
1513
+ }
1514
+ (function (Try) {
1515
+ function promise(block) {
1516
+ try {
1517
+ return block()
1518
+ .then(res => new Success(res))
1519
+ .catch(e => new Failure(e));
1520
+ }
1521
+ catch (e) {
1522
+ return Promise.resolve(new Failure(e));
1523
+ }
1524
+ }
1525
+ Try.promise = promise;
1526
+ })(Try || (Try = {}));
1527
+ function success(x) {
1528
+ return new Success(x);
1529
+ }
1530
+ function failure(x) {
1531
+ return new Failure(x);
1532
+ }
1533
+
1534
+ class Either {
1535
+ get isRight() {
1536
+ return !this.isLeft;
1537
+ }
1538
+ get left() {
1539
+ return new Either.LeftProjection(this);
1540
+ }
1541
+ fold(fa, fb) {
1542
+ return this.match({
1543
+ right: v => fb(v),
1544
+ left: e => fa(e)
1545
+ });
1546
+ }
1547
+ get swap() {
1548
+ return this.match({
1549
+ right: v => left(v),
1550
+ left: e => right(e)
1551
+ });
1552
+ }
1553
+ foreach(f) {
1554
+ this.match({
1555
+ right: b => f(b),
1556
+ left: () => {
1557
+ }
1558
+ });
1559
+ }
1560
+ getOrElse(or) {
1561
+ return this.match({
1562
+ right: b => b,
1563
+ left: () => or()
1564
+ });
1565
+ }
1566
+ getOrElseValue(or) {
1567
+ return this.match({
1568
+ right: b => b,
1569
+ left: () => or
1570
+ });
1571
+ }
1572
+ orElse(or) {
1573
+ return this.match({
1574
+ right: () => this,
1575
+ left: () => or()
1576
+ });
1577
+ }
1578
+ orElseValue(or) {
1579
+ return this.match({
1580
+ right: () => this,
1581
+ left: () => or
1582
+ });
1583
+ }
1584
+ contains(elem) {
1585
+ return this.match({
1586
+ right: b => elem === b,
1587
+ left: () => false
1588
+ });
1589
+ }
1590
+ forall(f) {
1591
+ return this.match({
1592
+ right: b => f(b),
1593
+ left: () => true
1594
+ });
1595
+ }
1596
+ exists(p) {
1597
+ return this.match({
1598
+ right: b => p(b),
1599
+ left: () => false
1600
+ });
1601
+ }
1602
+ flatMap(f) {
1603
+ return this.match({
1604
+ right: v => f(v),
1605
+ left: () => this
1606
+ });
1607
+ }
1608
+ flatMapPromise(f) {
1609
+ return this.match({
1610
+ right: v => f(v),
1611
+ left: () => Promise.resolve(this)
1612
+ });
1613
+ }
1614
+ map(f) {
1615
+ return this.match({
1616
+ right: v => right(f(v)),
1617
+ left: () => this
1618
+ });
1619
+ }
1620
+ async mapPromise(f) {
1621
+ return this.match({
1622
+ right: async (v) => right(await f(v)),
1623
+ left: () => Promise.resolve(this)
1624
+ });
1625
+ }
1626
+ filterOrElse(p, zero) {
1627
+ return this.match({
1628
+ right: (v) => p(v) ? this : left(zero()),
1629
+ left: () => this,
1630
+ });
1631
+ }
1632
+ filterOrElseValue(p, zero) {
1633
+ return this.match({
1634
+ right: (v) => p(v) ? this : left(zero),
1635
+ left: () => this,
1636
+ });
1637
+ }
1638
+ get toCollection() {
1639
+ return this.match({
1640
+ right: v => Collection.of(v),
1641
+ left: () => Collection.empty
1642
+ });
1643
+ }
1644
+ get toOption() {
1645
+ return this.match({
1646
+ right: v => some(v),
1647
+ left: () => none
1648
+ });
1649
+ }
1650
+ toTry(toError = toErrorConversion) {
1651
+ return this.match({
1652
+ right: (b) => success(b),
1653
+ left: (e) => failure(toError(e))
1654
+ });
1655
+ }
1656
+ }
1657
+ class Left extends Either {
1658
+ error;
1659
+ constructor(error) {
1660
+ super();
1661
+ this.error = error;
1662
+ }
1663
+ match(matcher) {
1664
+ return matcher.left(this.error);
1665
+ }
1666
+ get isLeft() {
1667
+ return true;
1668
+ }
1669
+ withRight() {
1670
+ return this;
1671
+ }
1672
+ }
1673
+ class Right extends Either {
1674
+ value;
1675
+ constructor(value) {
1676
+ super();
1677
+ this.value = value;
1678
+ }
1679
+ match(matcher) {
1680
+ return matcher.right(this.value);
1681
+ }
1682
+ get isLeft() {
1683
+ return false;
1684
+ }
1685
+ withLeft() {
1686
+ return this;
1687
+ }
1688
+ }
1689
+ (function (Either) {
1690
+ class LeftProjection {
1691
+ e;
1692
+ constructor(e) {
1693
+ this.e = e;
1694
+ }
1695
+ mapPromise(f) {
1696
+ return this.e.match({
1697
+ left: async (v) => left(await f(v)),
1698
+ right: () => Promise.resolve(this.e)
1699
+ });
1700
+ }
1701
+ flatMapPromise(f) {
1702
+ return this.e.match({
1703
+ left: v => f(v),
1704
+ right: () => Promise.resolve(this.e)
1705
+ });
1706
+ }
1707
+ foreach(f) {
1708
+ this.e.match({
1709
+ left: l => f(l),
1710
+ right: () => {
1711
+ }
1712
+ });
1713
+ }
1714
+ getOrElse(or) {
1715
+ return this.e.match({
1716
+ left: a => a,
1717
+ right: or
1718
+ });
1719
+ }
1720
+ getOrElseValue(or) {
1721
+ return this.e.match({
1722
+ left: a => a,
1723
+ right: () => or
1724
+ });
1725
+ }
1726
+ forall(p) {
1727
+ return this.e.match({
1728
+ left: (a) => p(a),
1729
+ right: () => true
1730
+ });
1731
+ }
1732
+ exists(p) {
1733
+ return this.e.match({
1734
+ left: (a) => p(a),
1735
+ right: () => false
1736
+ });
1737
+ }
1738
+ flatMap(f) {
1739
+ return this.e.match({
1740
+ left: (a) => f(a),
1741
+ right: () => this.e
1742
+ });
1743
+ }
1744
+ map(f) {
1745
+ return this.e.match({
1746
+ left: a => left(f(a)),
1747
+ right: () => this.e
1748
+ });
1749
+ }
1750
+ filterToOption(p) {
1751
+ return this.e.match({
1752
+ left: l => p(l) ? some(this.e) : none,
1753
+ right: () => none
1754
+ });
1755
+ }
1756
+ get toCollection() {
1757
+ return this.e.match({
1758
+ left: l => Collection.of(l),
1759
+ right: () => Nil
1760
+ });
1761
+ }
1762
+ get toOption() {
1763
+ return this.e.match({
1764
+ left: l => some(l),
1765
+ right: () => none
1766
+ });
1767
+ }
1768
+ }
1769
+ Either.LeftProjection = LeftProjection;
1770
+ })(Either || (Either = {}));
1771
+ function right(value) {
1772
+ return new Right(value);
1773
+ }
1774
+ function left(value) {
1775
+ return new Left(value);
1776
+ }
1777
+
1778
+ let HashMap$1 = class HashMap extends AbstractMap {
1779
+ constructor(map = new Map()) {
1780
+ super(map);
1781
+ }
1782
+ fromArray(array) {
1783
+ return HashMap.of(...array);
1784
+ }
1785
+ static of(...values) {
1786
+ return new HashMap(new Map(values));
1787
+ }
1788
+ static from(values) {
1789
+ return HashMap.of(...Array.from(values));
1790
+ }
1791
+ addAll(values) {
1792
+ for (const [key, value] of values) {
1793
+ this.map.set(key, value);
1794
+ }
1795
+ return this;
1796
+ }
1797
+ updateWith(key) {
1798
+ const previousValue = this.get(key);
1799
+ return (remappingFunction) => {
1800
+ const nextValue = remappingFunction(previousValue);
1801
+ if (previousValue.isEmpty && nextValue.isEmpty) {
1802
+ return nextValue;
1803
+ }
1804
+ else if (previousValue.isDefined && nextValue.isEmpty) {
1805
+ this.remove(key);
1806
+ return nextValue;
1807
+ }
1808
+ else {
1809
+ this.update(key, nextValue.get);
1810
+ return nextValue;
1811
+ }
1812
+ };
1813
+ }
1814
+ subtractAll(values) {
1815
+ if (this.isEmpty) {
1816
+ return this;
1817
+ }
1818
+ for (const key of values) {
1819
+ this.map.delete(key);
1820
+ if (this.isEmpty) {
1821
+ return this;
1822
+ }
1823
+ }
1824
+ return this;
1825
+ }
1826
+ clear() {
1827
+ this.map.clear();
1828
+ }
1829
+ clone() {
1830
+ const contentClone = new Map(this.map);
1831
+ return new HashMap(contentClone);
1832
+ }
1833
+ filterInPlace(p) {
1834
+ if (this.nonEmpty) {
1835
+ const entries = this.entries;
1836
+ entries.foreach(e => {
1837
+ if (!p(e)) {
1838
+ this.remove(e[0]);
1839
+ }
1840
+ });
1841
+ }
1842
+ return this;
1843
+ }
1844
+ mapValuesInPlace(f) {
1845
+ if (this.nonEmpty) {
1846
+ const entries = this.entries;
1847
+ entries.foreach(e => {
1848
+ this.update(e[0], f(e));
1849
+ });
1850
+ }
1851
+ return this;
1852
+ }
1853
+ getOrElseUpdate(key, defaultValue) {
1854
+ return this.get(key).getOrElse(() => {
1855
+ const newValue = defaultValue();
1856
+ this.map.set(key, newValue);
1857
+ return newValue;
1858
+ });
1859
+ }
1860
+ set(key, value) {
1861
+ this.map.set(key, value);
1862
+ return this;
1863
+ }
1864
+ put(key, value) {
1865
+ const res = this.get(key);
1866
+ this.map.set(key, value);
1867
+ return res;
1868
+ }
1869
+ remove(key) {
1870
+ const res = this.get(key);
1871
+ this.subtractOne(key);
1872
+ return res;
1873
+ }
1874
+ update(key, value) {
1875
+ this.map.set(key, value);
1876
+ }
1877
+ addOne(elem) {
1878
+ this.map.set(elem[0], elem[1]);
1879
+ return this;
1880
+ }
1881
+ subtractOne(key) {
1882
+ this.map.delete(key);
1883
+ return this;
1884
+ }
1885
+ get toImmutable() {
1886
+ return HashMap$2.of(...this.map.entries());
1887
+ }
1888
+ };
1889
+
1890
+ var mutable = /*#__PURE__*/Object.freeze({
1891
+ __proto__: null,
1892
+ ArrayBuffer: ArrayBuffer,
1893
+ HashMap: HashMap$1,
1894
+ HashSet: HashSet$2
1895
+ });
1896
+
1897
+ exports.ArrayBackedCollection = ArrayBackedCollection;
1898
+ exports.ArrayBuffer = ArrayBuffer;
1899
+ exports.Collection = Collection;
1900
+ exports.Either = Either;
1901
+ exports.Failure = Failure;
1902
+ exports.HashMap = HashMap$2;
1903
+ exports.HashSet = HashSet$1;
1904
+ exports.Left = Left;
1905
+ exports.Nil = Nil;
1906
+ exports.None = None;
1907
+ exports.Option = Option;
1908
+ exports.Right = Right;
1909
+ exports.Some = Some;
1910
+ exports.StepWithFilter = StepWithFilter;
1911
+ exports.Success = Success;
1912
+ exports.TaskWithFilter = TaskWithFilter;
1913
+ exports.Try = Try;
1914
+ exports.TryLike = TryLike;
1915
+ exports.failure = failure;
1916
+ exports.forComprehension = forComprehension;
1917
+ exports.identity = identity;
1918
+ exports.left = left;
1919
+ exports.mutable = mutable;
1920
+ exports.none = none;
1921
+ exports.option = option;
1922
+ exports.right = right;
1923
+ exports.some = some;
1924
+ exports.step = step;
1925
+ exports.success = success;
1926
+ exports.task = task;
1927
+ exports.toErrorConversion = toErrorConversion;