scats 1.4.0-dev → 1.4.1-dev
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/abstract-map.d.ts +4 -4
- package/dist/abstract-map.js +12 -15
- package/dist/abstract-set.d.ts +2 -2
- package/dist/abstract-set.js +6 -9
- package/dist/array-iterable.d.ts +1 -1
- package/dist/array-iterable.js +22 -26
- package/dist/collection.d.ts +4 -4
- package/dist/collection.js +50 -71
- package/dist/either.d.ts +4 -4
- package/dist/either.js +31 -39
- package/dist/hashmap.d.ts +2 -2
- package/dist/hashmap.js +9 -12
- package/dist/hashset.d.ts +3 -3
- package/dist/hashset.js +6 -11
- package/dist/index.d.ts +8 -8
- package/dist/index.js +9 -13
- package/dist/mappable.js +1 -2
- package/dist/mutable/hashmap.d.ts +3 -3
- package/dist/mutable/hashmap.js +3 -8
- package/dist/mutable/hashset.d.ts +2 -2
- package/dist/mutable/hashset.js +3 -8
- package/dist/mutable.d.ts +3 -3
- package/dist/mutable.js +3 -9
- package/dist/option.d.ts +6 -6
- package/dist/option.js +34 -44
- package/dist/try.d.ts +3 -3
- package/dist/try.js +27 -37
- package/dist/util.d.ts +2 -2
- package/dist/util.js +41 -50
- package/package.json +1 -1
- package/.eslintrc.cjs +0 -44
- package/coverage/clover.xml +0 -937
- package/coverage/coverage-final.json +0 -15
- package/coverage/lcov-report/array-iterable.ts.html +0 -1709
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/collection.ts.html +0 -1475
- package/coverage/lcov-report/either.ts.html +0 -1934
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hashmap.ts.html +0 -527
- package/coverage/lcov-report/hashset.ts.html +0 -392
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/index.ts.html +0 -101
- package/coverage/lcov-report/option.ts.html +0 -758
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/abstract-map.ts.html +0 -317
- package/coverage/lcov-report/src/abstract-set.ts.html +0 -200
- package/coverage/lcov-report/src/array-iterable.ts.html +0 -1751
- package/coverage/lcov-report/src/collection.ts.html +0 -1778
- package/coverage/lcov-report/src/either.ts.html +0 -1934
- package/coverage/lcov-report/src/hashmap.ts.html +0 -428
- package/coverage/lcov-report/src/hashset.ts.html +0 -482
- package/coverage/lcov-report/src/index.html +0 -276
- package/coverage/lcov-report/src/index.ts.html +0 -110
- package/coverage/lcov-report/src/mutable/hashmap.ts.html +0 -821
- package/coverage/lcov-report/src/mutable/hashset.ts.html +0 -611
- package/coverage/lcov-report/src/mutable/index.html +0 -126
- package/coverage/lcov-report/src/mutable.ts.html +0 -89
- package/coverage/lcov-report/src/option.ts.html +0 -758
- package/coverage/lcov-report/src/try.ts.html +0 -923
- package/coverage/lcov-report/src/util.ts.html +0 -518
- package/coverage/lcov-report/try.ts.html +0 -923
- package/coverage/lcov-report/util.ts.html +0 -518
- package/coverage/lcov.info +0 -2223
- package/jest.config.js +0 -32
- package/src/abstract-map.ts +0 -79
- package/src/abstract-set.ts +0 -40
- package/src/array-iterable.ts +0 -557
- package/src/collection.ts +0 -619
- package/src/either.ts +0 -618
- package/src/hashmap.ts +0 -116
- package/src/hashset.ts +0 -134
- package/src/index.ts +0 -10
- package/src/mappable.ts +0 -8
- package/src/mutable/hashmap.ts +0 -247
- package/src/mutable/hashset.ts +0 -177
- package/src/mutable.ts +0 -3
- package/src/option.ts +0 -226
- package/src/try.ts +0 -281
- package/src/util.ts +0 -146
package/dist/abstract-map.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ArrayIterable } from './array-iterable';
|
|
2
|
-
import { Option } from './option';
|
|
3
|
-
import { HashSet } from './hashset';
|
|
4
|
-
import { Collection } from './collection';
|
|
1
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
2
|
+
import { Option } from './option.js';
|
|
3
|
+
import { HashSet } from './hashset.js';
|
|
4
|
+
import { Collection } from './collection.js';
|
|
5
5
|
export declare type Tuple2<K, V> = [K, V];
|
|
6
6
|
export declare abstract class AbstractMap<K, V, S extends AbstractMap<K, V, any>> extends ArrayIterable<Tuple2<K, V>, S> {
|
|
7
7
|
protected readonly map: Map<K, V>;
|
package/dist/abstract-map.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const collection_1 = require("./collection");
|
|
8
|
-
class AbstractMap extends array_iterable_1.ArrayIterable {
|
|
1
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
2
|
+
import { option } from './option.js';
|
|
3
|
+
import { HashSet } from './hashset.js';
|
|
4
|
+
import { Collection } from './collection.js';
|
|
5
|
+
export class AbstractMap extends ArrayIterable {
|
|
6
|
+
map;
|
|
9
7
|
constructor(map) {
|
|
10
8
|
super();
|
|
11
9
|
this.map = map;
|
|
@@ -17,7 +15,7 @@ class AbstractMap extends array_iterable_1.ArrayIterable {
|
|
|
17
15
|
return this.map.size <= 0;
|
|
18
16
|
}
|
|
19
17
|
get(key) {
|
|
20
|
-
return
|
|
18
|
+
return option(this.map.get(key));
|
|
21
19
|
}
|
|
22
20
|
getOrElse(key, defaultValue) {
|
|
23
21
|
return this.get(key).getOrElse(defaultValue);
|
|
@@ -26,22 +24,22 @@ class AbstractMap extends array_iterable_1.ArrayIterable {
|
|
|
26
24
|
return this.get(key).getOrElseValue(defaultValue);
|
|
27
25
|
}
|
|
28
26
|
get keySet() {
|
|
29
|
-
return
|
|
27
|
+
return HashSet.of(...Array.from(this.map.keys()));
|
|
30
28
|
}
|
|
31
29
|
get keyIterator() {
|
|
32
30
|
return this.map.keys();
|
|
33
31
|
}
|
|
34
32
|
get keys() {
|
|
35
|
-
return new
|
|
33
|
+
return new Collection(Array.from(this.map.keys()));
|
|
36
34
|
}
|
|
37
35
|
get values() {
|
|
38
|
-
return new
|
|
36
|
+
return new Collection(Array.from(this.map.values()));
|
|
39
37
|
}
|
|
40
38
|
get valueIterator() {
|
|
41
39
|
return this.map.values();
|
|
42
40
|
}
|
|
43
41
|
get entries() {
|
|
44
|
-
return new
|
|
42
|
+
return new Collection(Array.from(this.map.entries()));
|
|
45
43
|
}
|
|
46
44
|
get entriesIterator() {
|
|
47
45
|
return this.map.entries();
|
|
@@ -50,7 +48,7 @@ class AbstractMap extends array_iterable_1.ArrayIterable {
|
|
|
50
48
|
return this.map.has(key);
|
|
51
49
|
}
|
|
52
50
|
get toCollection() {
|
|
53
|
-
return new
|
|
51
|
+
return new Collection(Array.from(this.map.entries()));
|
|
54
52
|
}
|
|
55
53
|
get toMap() {
|
|
56
54
|
return this.map;
|
|
@@ -59,4 +57,3 @@ class AbstractMap extends array_iterable_1.ArrayIterable {
|
|
|
59
57
|
return Array.from(this.map.entries());
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
|
-
exports.AbstractMap = AbstractMap;
|
package/dist/abstract-set.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArrayIterable } from './array-iterable';
|
|
2
|
-
import { ArrayBuffer, Collection } from './collection';
|
|
1
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
2
|
+
import { ArrayBuffer, Collection } from './collection.js';
|
|
3
3
|
export declare abstract class AbstractSet<T, S extends AbstractSet<T, any>> extends ArrayIterable<T, S> {
|
|
4
4
|
protected readonly items: Set<T>;
|
|
5
5
|
protected constructor(items: Set<T>);
|
package/dist/abstract-set.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const collection_1 = require("./collection");
|
|
6
|
-
class AbstractSet extends array_iterable_1.ArrayIterable {
|
|
1
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
2
|
+
import { ArrayBuffer, Collection } from './collection.js';
|
|
3
|
+
export class AbstractSet extends ArrayIterable {
|
|
4
|
+
items;
|
|
7
5
|
constructor(items) {
|
|
8
6
|
super();
|
|
9
7
|
this.items = items;
|
|
@@ -15,7 +13,7 @@ class AbstractSet extends array_iterable_1.ArrayIterable {
|
|
|
15
13
|
return Array.from(this.items.keys());
|
|
16
14
|
}
|
|
17
15
|
get toCollection() {
|
|
18
|
-
return new
|
|
16
|
+
return new Collection(Array.from(this.items.keys()));
|
|
19
17
|
}
|
|
20
18
|
get toSet() {
|
|
21
19
|
return new Set(this.items);
|
|
@@ -27,7 +25,6 @@ class AbstractSet extends array_iterable_1.ArrayIterable {
|
|
|
27
25
|
return this.items.size;
|
|
28
26
|
}
|
|
29
27
|
get toBuffer() {
|
|
30
|
-
return new
|
|
28
|
+
return new ArrayBuffer(Array.from(this.items.keys()));
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
exports.AbstractSet = AbstractSet;
|
package/dist/array-iterable.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, HashMap, Option } from './index';
|
|
1
|
+
import { Collection, HashMap, Option } from './index.js';
|
|
2
2
|
export declare abstract class ArrayIterable<T, C extends ArrayIterable<T, any>> implements Iterable<T> {
|
|
3
3
|
[Symbol.iterator](): Iterator<T, T | undefined, undefined>;
|
|
4
4
|
abstract get toArray(): Array<T>;
|
package/dist/array-iterable.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ArrayIterable = void 0;
|
|
4
|
-
const index_1 = require("./index");
|
|
5
|
-
class ArrayIterable {
|
|
1
|
+
import { Collection, HashMap, none, option, some } from './index.js';
|
|
2
|
+
export class ArrayIterable {
|
|
6
3
|
[Symbol.iterator]() {
|
|
7
4
|
let i = 0;
|
|
8
5
|
const items = this.toArray;
|
|
@@ -38,7 +35,7 @@ class ArrayIterable {
|
|
|
38
35
|
return this.toArray.find(i => p(i)) !== undefined;
|
|
39
36
|
}
|
|
40
37
|
find(p) {
|
|
41
|
-
return
|
|
38
|
+
return option(this.toArray.find(i => p(i)));
|
|
42
39
|
}
|
|
43
40
|
count(p) {
|
|
44
41
|
let res = 0;
|
|
@@ -65,7 +62,7 @@ class ArrayIterable {
|
|
|
65
62
|
return this.reduceLeftOption(op);
|
|
66
63
|
}
|
|
67
64
|
get headOption() {
|
|
68
|
-
return this.isEmpty ?
|
|
65
|
+
return this.isEmpty ? none : some(this.head);
|
|
69
66
|
}
|
|
70
67
|
get head() {
|
|
71
68
|
if (this.isEmpty) {
|
|
@@ -76,7 +73,7 @@ class ArrayIterable {
|
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
get lastOption() {
|
|
79
|
-
return this.isEmpty ?
|
|
76
|
+
return this.isEmpty ? none : some(this.last);
|
|
80
77
|
}
|
|
81
78
|
get last() {
|
|
82
79
|
if (this.isEmpty) {
|
|
@@ -100,11 +97,11 @@ class ArrayIterable {
|
|
|
100
97
|
return acc;
|
|
101
98
|
}
|
|
102
99
|
reduceLeftOption(op) {
|
|
103
|
-
return this.isEmpty ?
|
|
100
|
+
return this.isEmpty ? none : some(this.reduceLeft(op));
|
|
104
101
|
}
|
|
105
102
|
foldRight(initial) {
|
|
106
103
|
return (op) => {
|
|
107
|
-
return new
|
|
104
|
+
return new Collection(this.toArray)
|
|
108
105
|
.reverse
|
|
109
106
|
.foldLeft(initial)((a, n) => op(n, a));
|
|
110
107
|
};
|
|
@@ -123,7 +120,7 @@ class ArrayIterable {
|
|
|
123
120
|
return acc;
|
|
124
121
|
}
|
|
125
122
|
reduceRightOption(op) {
|
|
126
|
-
return this.isEmpty ?
|
|
123
|
+
return this.isEmpty ? none : some(this.reduceRight(op));
|
|
127
124
|
}
|
|
128
125
|
foldLeft(initial) {
|
|
129
126
|
return (op) => {
|
|
@@ -134,10 +131,10 @@ class ArrayIterable {
|
|
|
134
131
|
return this.foldLeft(initial);
|
|
135
132
|
}
|
|
136
133
|
groupBy(field) {
|
|
137
|
-
return this.foldLeft(
|
|
134
|
+
return this.foldLeft(HashMap.empty)((acc, next) => {
|
|
138
135
|
const key = field(next);
|
|
139
|
-
const existing = acc.get(key).getOrElseValue(
|
|
140
|
-
return acc.set(key, new
|
|
136
|
+
const existing = acc.get(key).getOrElseValue(Collection.empty);
|
|
137
|
+
return acc.set(key, new Collection(existing.toArray.concat(next)));
|
|
141
138
|
});
|
|
142
139
|
}
|
|
143
140
|
minBy(toNumber) {
|
|
@@ -158,7 +155,7 @@ class ArrayIterable {
|
|
|
158
155
|
}
|
|
159
156
|
}
|
|
160
157
|
minByOption(toNumber) {
|
|
161
|
-
return this.isEmpty ?
|
|
158
|
+
return this.isEmpty ? none : some(this.minBy(toNumber));
|
|
162
159
|
}
|
|
163
160
|
maxBy(toNumber) {
|
|
164
161
|
if (this.isEmpty) {
|
|
@@ -178,7 +175,7 @@ class ArrayIterable {
|
|
|
178
175
|
}
|
|
179
176
|
}
|
|
180
177
|
maxByOption(toNumber) {
|
|
181
|
-
return this.isEmpty ?
|
|
178
|
+
return this.isEmpty ? none : some(this.maxBy(toNumber));
|
|
182
179
|
}
|
|
183
180
|
partition(p) {
|
|
184
181
|
const array = this.toArray;
|
|
@@ -248,12 +245,12 @@ class ArrayIterable {
|
|
|
248
245
|
}
|
|
249
246
|
sliding(length, step = 1) {
|
|
250
247
|
if (this.isEmpty) {
|
|
251
|
-
return
|
|
248
|
+
return Collection.empty;
|
|
252
249
|
}
|
|
253
250
|
else {
|
|
254
251
|
const itemsSize = this.size;
|
|
255
252
|
if (itemsSize <= length) {
|
|
256
|
-
return
|
|
253
|
+
return Collection.of(this);
|
|
257
254
|
}
|
|
258
255
|
else {
|
|
259
256
|
const result = [];
|
|
@@ -267,7 +264,7 @@ class ArrayIterable {
|
|
|
267
264
|
left += step;
|
|
268
265
|
right = left + length;
|
|
269
266
|
}
|
|
270
|
-
return new
|
|
267
|
+
return new Collection(result);
|
|
271
268
|
}
|
|
272
269
|
}
|
|
273
270
|
}
|
|
@@ -309,9 +306,9 @@ class ArrayIterable {
|
|
|
309
306
|
}
|
|
310
307
|
groupMap(key) {
|
|
311
308
|
return (value) => {
|
|
312
|
-
return this.foldLeft(
|
|
309
|
+
return this.foldLeft(HashMap.empty)((acc, next) => {
|
|
313
310
|
const nextKey = key(next);
|
|
314
|
-
const existingColl = acc.getOrElse(nextKey, () =>
|
|
311
|
+
const existingColl = acc.getOrElse(nextKey, () => Collection.empty);
|
|
315
312
|
const updatedColl = existingColl.appended(value(next));
|
|
316
313
|
return acc.updated(nextKey, updatedColl);
|
|
317
314
|
});
|
|
@@ -320,7 +317,7 @@ class ArrayIterable {
|
|
|
320
317
|
groupMapReduce(key) {
|
|
321
318
|
return (value) => {
|
|
322
319
|
return (reduce) => {
|
|
323
|
-
return this.foldLeft(
|
|
320
|
+
return this.foldLeft(HashMap.empty)((acc, next) => {
|
|
324
321
|
const nextKey = key(next);
|
|
325
322
|
const nextValue = value(next);
|
|
326
323
|
return acc.updated(nextKey, acc.get(nextKey).map(e => reduce(e, nextValue)).getOrElseValue(nextValue));
|
|
@@ -359,7 +356,7 @@ class ArrayIterable {
|
|
|
359
356
|
for (let i = 0; i < array.length; i++) {
|
|
360
357
|
res.push([array[i], i]);
|
|
361
358
|
}
|
|
362
|
-
return new
|
|
359
|
+
return new Collection(res);
|
|
363
360
|
}
|
|
364
361
|
get tails() {
|
|
365
362
|
const array = this.toArray;
|
|
@@ -367,7 +364,7 @@ class ArrayIterable {
|
|
|
367
364
|
for (let i = 0; i <= array.length; i++) {
|
|
368
365
|
res.push(this.takeRight(array.length - i));
|
|
369
366
|
}
|
|
370
|
-
return new
|
|
367
|
+
return new Collection(res);
|
|
371
368
|
}
|
|
372
369
|
get inits() {
|
|
373
370
|
const array = this.toArray;
|
|
@@ -375,7 +372,6 @@ class ArrayIterable {
|
|
|
375
372
|
for (let i = 0; i <= array.length; i++) {
|
|
376
373
|
res.push(this.take(array.length - i));
|
|
377
374
|
}
|
|
378
|
-
return new
|
|
375
|
+
return new Collection(res);
|
|
379
376
|
}
|
|
380
377
|
}
|
|
381
|
-
exports.ArrayIterable = ArrayIterable;
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Mappable } from './mappable';
|
|
2
|
-
import { HashMap, HashSet, Option } from './index';
|
|
3
|
-
import { Filterable } from './util';
|
|
4
|
-
import { ArrayIterable } from './array-iterable';
|
|
1
|
+
import { Mappable } from './mappable.js';
|
|
2
|
+
import { HashMap, HashSet, Option } from './index.js';
|
|
3
|
+
import { Filterable } from './util.js';
|
|
4
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
5
5
|
export declare abstract class ArrayBackedCollection<T, C extends ArrayIterable<T, any>> extends ArrayIterable<T, C> {
|
|
6
6
|
protected abstract readonly items: T[];
|
|
7
7
|
protected checkWithinBounds(lo: number, hi: number): void;
|
package/dist/collection.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const index_1 = require("./index");
|
|
6
|
-
const array_iterable_1 = require("./array-iterable");
|
|
7
|
-
class ArrayBackedCollection extends array_iterable_1.ArrayIterable {
|
|
1
|
+
import { HashMap, HashSet } from './index.js';
|
|
2
|
+
import { ArrayIterable } from './array-iterable.js';
|
|
3
|
+
export class ArrayBackedCollection extends ArrayIterable {
|
|
8
4
|
checkWithinBounds(lo, hi) {
|
|
9
5
|
if (lo < 0)
|
|
10
6
|
throw new Error(`$lo is out of bounds (min 0, max ${this.items.length - 1})`);
|
|
@@ -22,7 +18,7 @@ class ArrayBackedCollection extends array_iterable_1.ArrayIterable {
|
|
|
22
18
|
return this.items[index];
|
|
23
19
|
}
|
|
24
20
|
get toSet() {
|
|
25
|
-
return
|
|
21
|
+
return HashSet.of(...this.items);
|
|
26
22
|
}
|
|
27
23
|
indexOf(item) {
|
|
28
24
|
return this.items.indexOf(item);
|
|
@@ -70,15 +66,16 @@ class ArrayBackedCollection extends array_iterable_1.ArrayIterable {
|
|
|
70
66
|
return this.size;
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
export class Collection extends ArrayBackedCollection {
|
|
70
|
+
items;
|
|
75
71
|
constructor(items) {
|
|
76
72
|
super();
|
|
77
73
|
this.items = items;
|
|
78
74
|
}
|
|
75
|
+
static empty = new Collection([]);
|
|
79
76
|
fromArray(array) {
|
|
80
77
|
if (!array || array.length <= 0) {
|
|
81
|
-
return
|
|
78
|
+
return Nil;
|
|
82
79
|
}
|
|
83
80
|
else {
|
|
84
81
|
return new Collection(array);
|
|
@@ -118,34 +115,26 @@ class Collection extends ArrayBackedCollection {
|
|
|
118
115
|
});
|
|
119
116
|
return new Collection(res);
|
|
120
117
|
}
|
|
121
|
-
mapPromise(f) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return new Collection(res);
|
|
128
|
-
});
|
|
118
|
+
async mapPromise(f) {
|
|
119
|
+
const res = [];
|
|
120
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
121
|
+
res.push(await f(this.items[i]));
|
|
122
|
+
}
|
|
123
|
+
return new Collection(res);
|
|
129
124
|
}
|
|
130
|
-
mapPromiseAll(f) {
|
|
131
|
-
return (
|
|
132
|
-
return new Collection(yield Promise.all(this.items.map(i => f(i))));
|
|
133
|
-
});
|
|
125
|
+
async mapPromiseAll(f) {
|
|
126
|
+
return new Collection(await Promise.all(this.items.map(i => f(i))));
|
|
134
127
|
}
|
|
135
|
-
flatMapPromise(f) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return new Collection(res);
|
|
143
|
-
});
|
|
128
|
+
async flatMapPromise(f) {
|
|
129
|
+
let res = [];
|
|
130
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
131
|
+
const item = this.items[i];
|
|
132
|
+
res = res.concat((await f(item)).items);
|
|
133
|
+
}
|
|
134
|
+
return new Collection(res);
|
|
144
135
|
}
|
|
145
|
-
flatMapPromiseAll(f) {
|
|
146
|
-
return (
|
|
147
|
-
return (yield this.mapPromiseAll(f)).flatten();
|
|
148
|
-
});
|
|
136
|
+
async flatMapPromiseAll(f) {
|
|
137
|
+
return (await this.mapPromiseAll(f)).flatten();
|
|
149
138
|
}
|
|
150
139
|
flatten() {
|
|
151
140
|
const res = [];
|
|
@@ -163,7 +152,7 @@ class Collection extends ArrayBackedCollection {
|
|
|
163
152
|
return new ArrayBuffer(this.items);
|
|
164
153
|
}
|
|
165
154
|
toMap(mapper) {
|
|
166
|
-
return
|
|
155
|
+
return HashMap.of(...this.map(mapper).toArray);
|
|
167
156
|
}
|
|
168
157
|
zip(that) {
|
|
169
158
|
const res = [];
|
|
@@ -183,17 +172,16 @@ class Collection extends ArrayBackedCollection {
|
|
|
183
172
|
return new Collection(res);
|
|
184
173
|
}
|
|
185
174
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
175
|
+
export const Nil = Collection.empty;
|
|
176
|
+
export class ArrayBuffer extends ArrayBackedCollection {
|
|
177
|
+
items;
|
|
178
|
+
static get empty() {
|
|
179
|
+
return new ArrayBuffer([]);
|
|
180
|
+
}
|
|
190
181
|
constructor(items = []) {
|
|
191
182
|
super();
|
|
192
183
|
this.items = items;
|
|
193
184
|
}
|
|
194
|
-
static get empty() {
|
|
195
|
-
return new ArrayBuffer([]);
|
|
196
|
-
}
|
|
197
185
|
static of(...elements) {
|
|
198
186
|
return new ArrayBuffer(elements);
|
|
199
187
|
}
|
|
@@ -344,37 +332,29 @@ class ArrayBuffer extends ArrayBackedCollection {
|
|
|
344
332
|
});
|
|
345
333
|
return new ArrayBuffer(res);
|
|
346
334
|
}
|
|
347
|
-
flatMapPromise(f) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return new ArrayBuffer(res);
|
|
355
|
-
});
|
|
335
|
+
async flatMapPromise(f) {
|
|
336
|
+
let res = [];
|
|
337
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
338
|
+
const item = this.items[i];
|
|
339
|
+
res = res.concat((await f(item)).items);
|
|
340
|
+
}
|
|
341
|
+
return new ArrayBuffer(res);
|
|
356
342
|
}
|
|
357
343
|
map(f) {
|
|
358
344
|
return new ArrayBuffer(this.items.map(i => f(i)));
|
|
359
345
|
}
|
|
360
|
-
mapPromise(f) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return new ArrayBuffer(res);
|
|
367
|
-
});
|
|
346
|
+
async mapPromise(f) {
|
|
347
|
+
const res = [];
|
|
348
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
349
|
+
res.push(await f(this.items[i]));
|
|
350
|
+
}
|
|
351
|
+
return new ArrayBuffer(res);
|
|
368
352
|
}
|
|
369
|
-
mapPromiseAll(f) {
|
|
370
|
-
return (
|
|
371
|
-
return new ArrayBuffer(yield Promise.all(this.items.map(i => f(i))));
|
|
372
|
-
});
|
|
353
|
+
async mapPromiseAll(f) {
|
|
354
|
+
return new ArrayBuffer(await Promise.all(this.items.map(i => f(i))));
|
|
373
355
|
}
|
|
374
|
-
flatMapPromiseAll(f) {
|
|
375
|
-
return (
|
|
376
|
-
return (yield this.mapPromiseAll(f)).flatten();
|
|
377
|
-
});
|
|
356
|
+
async flatMapPromiseAll(f) {
|
|
357
|
+
return (await this.mapPromiseAll(f)).flatten();
|
|
378
358
|
}
|
|
379
359
|
flatten() {
|
|
380
360
|
const res = [];
|
|
@@ -389,7 +369,6 @@ class ArrayBuffer extends ArrayBackedCollection {
|
|
|
389
369
|
return new ArrayBuffer(res);
|
|
390
370
|
}
|
|
391
371
|
toMap(mapper) {
|
|
392
|
-
return
|
|
372
|
+
return HashMap.of(...this.map(mapper).toArray);
|
|
393
373
|
}
|
|
394
374
|
}
|
|
395
|
-
exports.ArrayBuffer = ArrayBuffer;
|
package/dist/either.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Option } from './option';
|
|
2
|
-
import { Collection } from './collection';
|
|
3
|
-
import { TryLike } from './try';
|
|
4
|
-
import { Mappable } from './mappable';
|
|
1
|
+
import { Option } from './option.js';
|
|
2
|
+
import { Collection } from './collection.js';
|
|
3
|
+
import { TryLike } from './try.js';
|
|
4
|
+
import { Mappable } from './mappable.js';
|
|
5
5
|
export interface EitherMatch<LEFT, RIGHT, T> {
|
|
6
6
|
right: (right: RIGHT) => T;
|
|
7
7
|
left: (left: LEFT) => T;
|
package/dist/either.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const collection_1 = require("./collection");
|
|
7
|
-
const try_1 = require("./try");
|
|
8
|
-
const util_1 = require("./util");
|
|
9
|
-
class Either {
|
|
1
|
+
import { none, some } from './option.js';
|
|
2
|
+
import { Collection, Nil } from './collection.js';
|
|
3
|
+
import { failure, success } from './try.js';
|
|
4
|
+
import { toErrorConversion } from './util.js';
|
|
5
|
+
export class Either {
|
|
10
6
|
get isRight() {
|
|
11
7
|
return !this.isLeft;
|
|
12
8
|
}
|
|
@@ -92,12 +88,10 @@ class Either {
|
|
|
92
88
|
left: () => this
|
|
93
89
|
});
|
|
94
90
|
}
|
|
95
|
-
mapPromise(f) {
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
left: () => Promise.resolve(this)
|
|
100
|
-
});
|
|
91
|
+
async mapPromise(f) {
|
|
92
|
+
return this.match({
|
|
93
|
+
right: async (v) => right(await f(v)),
|
|
94
|
+
left: () => Promise.resolve(this)
|
|
101
95
|
});
|
|
102
96
|
}
|
|
103
97
|
filterOrElse(p, zero) {
|
|
@@ -114,25 +108,25 @@ class Either {
|
|
|
114
108
|
}
|
|
115
109
|
get toCollection() {
|
|
116
110
|
return this.match({
|
|
117
|
-
right: v =>
|
|
118
|
-
left: () =>
|
|
111
|
+
right: v => Collection.of(v),
|
|
112
|
+
left: () => Collection.empty
|
|
119
113
|
});
|
|
120
114
|
}
|
|
121
115
|
get toOption() {
|
|
122
116
|
return this.match({
|
|
123
|
-
right: v =>
|
|
124
|
-
left: () =>
|
|
117
|
+
right: v => some(v),
|
|
118
|
+
left: () => none
|
|
125
119
|
});
|
|
126
120
|
}
|
|
127
|
-
toTry(toError =
|
|
121
|
+
toTry(toError = toErrorConversion) {
|
|
128
122
|
return this.match({
|
|
129
|
-
right: (b) =>
|
|
130
|
-
left: (e) =>
|
|
123
|
+
right: (b) => success(b),
|
|
124
|
+
left: (e) => failure(toError(e))
|
|
131
125
|
});
|
|
132
126
|
}
|
|
133
127
|
}
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
export class Left extends Either {
|
|
129
|
+
error;
|
|
136
130
|
constructor(error) {
|
|
137
131
|
super();
|
|
138
132
|
this.error = error;
|
|
@@ -147,8 +141,8 @@ class Left extends Either {
|
|
|
147
141
|
return this;
|
|
148
142
|
}
|
|
149
143
|
}
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
export class Right extends Either {
|
|
145
|
+
value;
|
|
152
146
|
constructor(value) {
|
|
153
147
|
super();
|
|
154
148
|
this.value = value;
|
|
@@ -163,15 +157,15 @@ class Right extends Either {
|
|
|
163
157
|
return this;
|
|
164
158
|
}
|
|
165
159
|
}
|
|
166
|
-
exports.Right = Right;
|
|
167
160
|
(function (Either) {
|
|
168
161
|
class LeftProjection {
|
|
162
|
+
e;
|
|
169
163
|
constructor(e) {
|
|
170
164
|
this.e = e;
|
|
171
165
|
}
|
|
172
166
|
mapPromise(f) {
|
|
173
167
|
return this.e.match({
|
|
174
|
-
left: (v) =>
|
|
168
|
+
left: async (v) => left(await f(v)),
|
|
175
169
|
right: () => Promise.resolve(this.e)
|
|
176
170
|
});
|
|
177
171
|
}
|
|
@@ -226,30 +220,28 @@ exports.Right = Right;
|
|
|
226
220
|
}
|
|
227
221
|
filterToOption(p) {
|
|
228
222
|
return this.e.match({
|
|
229
|
-
left: l => p(l) ?
|
|
230
|
-
right: () =>
|
|
223
|
+
left: l => p(l) ? some(this.e) : none,
|
|
224
|
+
right: () => none
|
|
231
225
|
});
|
|
232
226
|
}
|
|
233
227
|
get toCollection() {
|
|
234
228
|
return this.e.match({
|
|
235
|
-
left: l =>
|
|
236
|
-
right: () =>
|
|
229
|
+
left: l => Collection.of(l),
|
|
230
|
+
right: () => Nil
|
|
237
231
|
});
|
|
238
232
|
}
|
|
239
233
|
get toOption() {
|
|
240
234
|
return this.e.match({
|
|
241
|
-
left: l =>
|
|
242
|
-
right: () =>
|
|
235
|
+
left: l => some(l),
|
|
236
|
+
right: () => none
|
|
243
237
|
});
|
|
244
238
|
}
|
|
245
239
|
}
|
|
246
240
|
Either.LeftProjection = LeftProjection;
|
|
247
|
-
})(Either
|
|
248
|
-
function right(value) {
|
|
241
|
+
})(Either || (Either = {}));
|
|
242
|
+
export function right(value) {
|
|
249
243
|
return new Right(value);
|
|
250
244
|
}
|
|
251
|
-
|
|
252
|
-
function left(value) {
|
|
245
|
+
export function left(value) {
|
|
253
246
|
return new Left(value);
|
|
254
247
|
}
|
|
255
|
-
exports.left = left;
|
package/dist/hashmap.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mutable, Option } from './index';
|
|
2
|
-
import { AbstractMap, Tuple2 } from './abstract-map';
|
|
1
|
+
import { mutable, Option } from './index.js';
|
|
2
|
+
import { AbstractMap, Tuple2 } from './abstract-map.js';
|
|
3
3
|
export declare class HashMap<K, V> extends AbstractMap<K, V, HashMap<K, V>> {
|
|
4
4
|
protected readonly map: Map<K, V>;
|
|
5
5
|
protected fromArray(array: Tuple2<K, V>[]): HashMap<K, V>;
|