scats 1.0.32 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -3
- package/coverage/clover.xml +937 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/lcov-report/array-iterable.ts.html +1709 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/collection.ts.html +1475 -0
- package/coverage/lcov-report/either.ts.html +1934 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hashmap.ts.html +527 -0
- package/coverage/lcov-report/hashset.ts.html +392 -0
- package/coverage/lcov-report/index.html +126 -0
- package/coverage/lcov-report/index.ts.html +101 -0
- package/coverage/lcov-report/option.ts.html +758 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/src/abstract-map.ts.html +317 -0
- package/coverage/lcov-report/src/abstract-set.ts.html +200 -0
- package/coverage/lcov-report/src/array-iterable.ts.html +1751 -0
- package/coverage/lcov-report/src/collection.ts.html +1778 -0
- package/coverage/lcov-report/src/either.ts.html +1934 -0
- package/coverage/lcov-report/src/hashmap.ts.html +428 -0
- package/coverage/lcov-report/src/hashset.ts.html +482 -0
- package/coverage/lcov-report/src/index.html +276 -0
- package/coverage/lcov-report/src/index.ts.html +110 -0
- package/coverage/lcov-report/src/mutable/hashmap.ts.html +821 -0
- package/coverage/lcov-report/src/mutable/hashset.ts.html +611 -0
- package/coverage/lcov-report/src/mutable/index.html +126 -0
- package/coverage/lcov-report/src/mutable.ts.html +89 -0
- package/coverage/lcov-report/src/option.ts.html +758 -0
- package/coverage/lcov-report/src/try.ts.html +923 -0
- package/coverage/lcov-report/src/util.ts.html +518 -0
- package/coverage/lcov-report/try.ts.html +923 -0
- package/coverage/lcov-report/util.ts.html +518 -0
- package/coverage/lcov.info +2223 -0
- package/dist/abstract-map.d.ts +25 -0
- package/dist/abstract-map.js +62 -0
- package/dist/abstract-set.d.ts +13 -0
- package/dist/abstract-set.js +33 -0
- package/dist/array-iterable.d.ts +1 -3
- package/dist/array-iterable.js +21 -23
- package/dist/collection.d.ts +59 -20
- package/dist/collection.js +254 -62
- package/dist/hashmap.d.ts +12 -26
- package/dist/hashmap.js +39 -58
- package/dist/hashset.d.ts +12 -17
- package/dist/hashset.js +25 -35
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/mutable/hashmap.d.ts +24 -0
- package/dist/mutable/hashmap.js +118 -0
- package/dist/mutable/hashset.d.ts +20 -0
- package/dist/mutable/hashset.js +88 -0
- package/dist/mutable.d.ts +3 -0
- package/dist/mutable.js +9 -0
- package/dist/option.js +1 -1
- package/package.json +12 -12
- package/src/abstract-map.ts +79 -0
- package/src/abstract-set.ts +40 -0
- package/src/array-iterable.ts +26 -12
- package/src/collection.ts +394 -85
- package/src/either.ts +2 -2
- package/src/hashmap.ts +74 -73
- package/src/hashset.ts +82 -42
- package/src/index.ts +3 -0
- package/src/mutable/hashmap.ts +247 -0
- package/src/mutable/hashset.ts +177 -0
- package/src/mutable.ts +3 -0
- package/src/option.ts +2 -2
- package/src/try.ts +9 -9
package/dist/collection.js
CHANGED
|
@@ -1,11 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Nil = exports.Collection = void 0;
|
|
3
|
+
exports.ArrayBuffer = exports.Nil = exports.Collection = exports.ArrayBackedCollection = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const hashset_1 = require("./hashset");
|
|
5
|
+
const index_1 = require("./index");
|
|
7
6
|
const array_iterable_1 = require("./array-iterable");
|
|
8
|
-
class
|
|
7
|
+
class ArrayBackedCollection extends array_iterable_1.ArrayIterable {
|
|
8
|
+
checkWithinBounds(lo, hi) {
|
|
9
|
+
if (lo < 0)
|
|
10
|
+
throw new Error(`$lo is out of bounds (min 0, max ${this.items.length - 1})`);
|
|
11
|
+
if (hi > this.size)
|
|
12
|
+
throw new Error(`$lo is out of bounds (min 0, max ${this.items.length - 1})`);
|
|
13
|
+
}
|
|
14
|
+
get reverse() {
|
|
15
|
+
return this.fromArray(this.items.reverse());
|
|
16
|
+
}
|
|
17
|
+
get toArray() {
|
|
18
|
+
return this.items;
|
|
19
|
+
}
|
|
20
|
+
get(index) {
|
|
21
|
+
this.checkWithinBounds(index, index + 1);
|
|
22
|
+
return this.items[index];
|
|
23
|
+
}
|
|
24
|
+
get toSet() {
|
|
25
|
+
return index_1.HashSet.of(...this.items);
|
|
26
|
+
}
|
|
27
|
+
indexOf(item) {
|
|
28
|
+
return this.items.indexOf(item);
|
|
29
|
+
}
|
|
30
|
+
get distinct() {
|
|
31
|
+
return this.fromArray(Array.from(new Set(this.items)));
|
|
32
|
+
}
|
|
33
|
+
distinctBy(key) {
|
|
34
|
+
const keys = new Set();
|
|
35
|
+
const res = [];
|
|
36
|
+
this.foreach(item => {
|
|
37
|
+
const currentKey = key(item);
|
|
38
|
+
if (!keys.has(currentKey)) {
|
|
39
|
+
keys.add(currentKey);
|
|
40
|
+
res.push(item);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return this.fromArray(res);
|
|
44
|
+
}
|
|
45
|
+
appended(item) {
|
|
46
|
+
return this.fromArray(this.items.concat([item]));
|
|
47
|
+
}
|
|
48
|
+
appendedAll(other) {
|
|
49
|
+
return this.fromArray(this.items.concat(...other));
|
|
50
|
+
}
|
|
51
|
+
prepended(item) {
|
|
52
|
+
return this.fromArray([item].concat(this.items));
|
|
53
|
+
}
|
|
54
|
+
prependedAll(other) {
|
|
55
|
+
return this.fromArray(Array.from(other).concat(this.items));
|
|
56
|
+
}
|
|
57
|
+
concat(other) {
|
|
58
|
+
return this.appendedAll(other);
|
|
59
|
+
}
|
|
60
|
+
slice(from, until) {
|
|
61
|
+
return this.fromArray(this.items.slice(from, until));
|
|
62
|
+
}
|
|
63
|
+
sort(param) {
|
|
64
|
+
return this.fromArray(this.items.slice(0).sort(param));
|
|
65
|
+
}
|
|
66
|
+
sortBy(fieldToNumber) {
|
|
67
|
+
return this.sort(((a, b) => fieldToNumber(a) - fieldToNumber(b)));
|
|
68
|
+
}
|
|
69
|
+
get length() {
|
|
70
|
+
return this.size;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.ArrayBackedCollection = ArrayBackedCollection;
|
|
74
|
+
class Collection extends ArrayBackedCollection {
|
|
9
75
|
constructor(items) {
|
|
10
76
|
super();
|
|
11
77
|
this.items = items;
|
|
@@ -21,6 +87,9 @@ class Collection extends array_iterable_1.ArrayIterable {
|
|
|
21
87
|
static of(...items) {
|
|
22
88
|
return new Collection(items);
|
|
23
89
|
}
|
|
90
|
+
static from(elements) {
|
|
91
|
+
return new Collection(Array.from(elements));
|
|
92
|
+
}
|
|
24
93
|
static fill(len) {
|
|
25
94
|
return function (elem) {
|
|
26
95
|
const res = new Array(len);
|
|
@@ -30,16 +99,22 @@ class Collection extends array_iterable_1.ArrayIterable {
|
|
|
30
99
|
return new Collection(res);
|
|
31
100
|
};
|
|
32
101
|
}
|
|
33
|
-
slice(from, until) {
|
|
34
|
-
return new Collection(this.items.slice(from, until));
|
|
35
|
-
}
|
|
36
102
|
map(f) {
|
|
37
103
|
return new Collection(this.items.map(i => f(i)));
|
|
38
104
|
}
|
|
39
105
|
flatMap(f) {
|
|
40
|
-
|
|
106
|
+
const res = [];
|
|
107
|
+
this.items.forEach(i => {
|
|
108
|
+
res.push(...f(i).items);
|
|
109
|
+
});
|
|
110
|
+
return new Collection(res);
|
|
111
|
+
}
|
|
112
|
+
flatMapOption(f) {
|
|
113
|
+
const res = [];
|
|
41
114
|
this.items.forEach(i => {
|
|
42
|
-
|
|
115
|
+
f(i).foreach(v => {
|
|
116
|
+
res.push(v);
|
|
117
|
+
});
|
|
43
118
|
});
|
|
44
119
|
return new Collection(res);
|
|
45
120
|
}
|
|
@@ -59,10 +134,10 @@ class Collection extends array_iterable_1.ArrayIterable {
|
|
|
59
134
|
}
|
|
60
135
|
flatMapPromise(f) {
|
|
61
136
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
|
|
137
|
+
const res = [];
|
|
63
138
|
for (let i = 0; i < this.items.length; i++) {
|
|
64
139
|
const item = this.items[i];
|
|
65
|
-
res
|
|
140
|
+
res.push(...(yield f(item)).items);
|
|
66
141
|
}
|
|
67
142
|
return new Collection(res);
|
|
68
143
|
});
|
|
@@ -84,59 +159,11 @@ class Collection extends array_iterable_1.ArrayIterable {
|
|
|
84
159
|
});
|
|
85
160
|
return new Collection(res);
|
|
86
161
|
}
|
|
87
|
-
get(
|
|
88
|
-
return this.items
|
|
89
|
-
}
|
|
90
|
-
get toArray() {
|
|
91
|
-
return this.items;
|
|
92
|
-
}
|
|
93
|
-
get reverse() {
|
|
94
|
-
return new Collection(this.items.reverse());
|
|
95
|
-
}
|
|
96
|
-
sort(param) {
|
|
97
|
-
return new Collection(this.items.sort(param));
|
|
98
|
-
}
|
|
99
|
-
sortBy(fieldToNumber) {
|
|
100
|
-
return this.sort((a, b) => fieldToNumber(a) - fieldToNumber(b));
|
|
101
|
-
}
|
|
102
|
-
appended(item) {
|
|
103
|
-
return new Collection(this.items.concat([item]));
|
|
104
|
-
}
|
|
105
|
-
appendedAll(other) {
|
|
106
|
-
return new Collection(this.items.concat(other.items));
|
|
107
|
-
}
|
|
108
|
-
prepended(item) {
|
|
109
|
-
return new Collection([item].concat(this.items));
|
|
110
|
-
}
|
|
111
|
-
prependedAll(other) {
|
|
112
|
-
return new Collection(other.items.concat(this.items));
|
|
113
|
-
}
|
|
114
|
-
concat(other) {
|
|
115
|
-
return this.appendedAll(other);
|
|
116
|
-
}
|
|
117
|
-
get toSet() {
|
|
118
|
-
return hashset_1.HashSet.of(...this.items);
|
|
119
|
-
}
|
|
120
|
-
get distinct() {
|
|
121
|
-
return hashset_1.HashSet.of(...this.items).toCollection;
|
|
122
|
-
}
|
|
123
|
-
distinctBy(key) {
|
|
124
|
-
const keys = new Set();
|
|
125
|
-
const res = [];
|
|
126
|
-
this.foreach(item => {
|
|
127
|
-
const currentKey = key(item);
|
|
128
|
-
if (!keys.has(currentKey)) {
|
|
129
|
-
keys.add(currentKey);
|
|
130
|
-
res.push(item);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
return new Collection(res);
|
|
162
|
+
get toBuffer() {
|
|
163
|
+
return new ArrayBuffer(this.items);
|
|
134
164
|
}
|
|
135
165
|
toMap(mapper) {
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
indexOf(item) {
|
|
139
|
-
return this.items.indexOf(item);
|
|
166
|
+
return index_1.HashMap.of(...this.map(mapper).toArray);
|
|
140
167
|
}
|
|
141
168
|
zip(that) {
|
|
142
169
|
const res = [];
|
|
@@ -159,3 +186,168 @@ class Collection extends array_iterable_1.ArrayIterable {
|
|
|
159
186
|
exports.Collection = Collection;
|
|
160
187
|
Collection.empty = new Collection([]);
|
|
161
188
|
exports.Nil = Collection.empty;
|
|
189
|
+
class ArrayBuffer extends ArrayBackedCollection {
|
|
190
|
+
constructor(items) {
|
|
191
|
+
super();
|
|
192
|
+
this.items = items;
|
|
193
|
+
}
|
|
194
|
+
static get empty() {
|
|
195
|
+
return new ArrayBuffer([]);
|
|
196
|
+
}
|
|
197
|
+
static of(...elements) {
|
|
198
|
+
return new ArrayBuffer(elements);
|
|
199
|
+
}
|
|
200
|
+
static from(elements) {
|
|
201
|
+
return new ArrayBuffer(Array.from(elements));
|
|
202
|
+
}
|
|
203
|
+
static fill(len) {
|
|
204
|
+
return function (elem) {
|
|
205
|
+
const res = new Array(len);
|
|
206
|
+
for (let i = 0; i < len; i++) {
|
|
207
|
+
res[i] = elem(i);
|
|
208
|
+
}
|
|
209
|
+
return new ArrayBuffer(res);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
fromArray(array) {
|
|
213
|
+
if (!array || array.length <= 0) {
|
|
214
|
+
return new ArrayBuffer([]);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return new ArrayBuffer(array);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
update(index, element) {
|
|
221
|
+
this.checkWithinBounds(index, index + 1);
|
|
222
|
+
this.items[index] = element;
|
|
223
|
+
}
|
|
224
|
+
set(index, element) {
|
|
225
|
+
this.update(index, element);
|
|
226
|
+
}
|
|
227
|
+
clear() {
|
|
228
|
+
this.items.length = 0;
|
|
229
|
+
}
|
|
230
|
+
append(element) {
|
|
231
|
+
this.items.push(element);
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
appendAll(elements) {
|
|
235
|
+
this.items.push(...elements);
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
prepend(element) {
|
|
239
|
+
this.items.unshift(element);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
prependAll(elements) {
|
|
243
|
+
this.items.unshift(...elements);
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
insert(idx, element) {
|
|
247
|
+
this.checkWithinBounds(idx, idx);
|
|
248
|
+
this.items.splice(idx, 0, element);
|
|
249
|
+
}
|
|
250
|
+
insertAll(idx, elements) {
|
|
251
|
+
this.checkWithinBounds(idx, idx);
|
|
252
|
+
this.items.splice(idx, 0, ...elements);
|
|
253
|
+
}
|
|
254
|
+
remove(index, count = 1) {
|
|
255
|
+
if (count > 0) {
|
|
256
|
+
this.checkWithinBounds(index, index + 1);
|
|
257
|
+
this.items.splice(index, count);
|
|
258
|
+
}
|
|
259
|
+
else if (count < 0) {
|
|
260
|
+
throw new Error('removing negative number of elements: ' + count);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
subtractOne(element) {
|
|
264
|
+
const i = this.items.indexOf(element);
|
|
265
|
+
if (i != -1) {
|
|
266
|
+
this.remove(i);
|
|
267
|
+
}
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
subtractAll(elements) {
|
|
271
|
+
if (elements === this || elements === this.items) {
|
|
272
|
+
const buf = new ArrayBuffer(Array.from(elements));
|
|
273
|
+
buf.foreach(e => this.subtractOne(e));
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
for (const element of elements) {
|
|
277
|
+
this.subtractOne(element);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
sort(compareFn) {
|
|
283
|
+
this.items.sort(compareFn);
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
get toCollection() {
|
|
287
|
+
return new Collection(this.items.slice(0));
|
|
288
|
+
}
|
|
289
|
+
flatMap(f) {
|
|
290
|
+
const res = [];
|
|
291
|
+
this.items.forEach(i => {
|
|
292
|
+
res.push(...f(i).items);
|
|
293
|
+
});
|
|
294
|
+
return new ArrayBuffer(res);
|
|
295
|
+
}
|
|
296
|
+
flatMapOption(f) {
|
|
297
|
+
const res = [];
|
|
298
|
+
this.items.forEach(i => {
|
|
299
|
+
f(i).foreach(v => {
|
|
300
|
+
res.push(v);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
return new ArrayBuffer(res);
|
|
304
|
+
}
|
|
305
|
+
flatMapPromise(f) {
|
|
306
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
307
|
+
const res = [];
|
|
308
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
309
|
+
const item = this.items[i];
|
|
310
|
+
res.push(...(yield f(item)).items);
|
|
311
|
+
}
|
|
312
|
+
return new ArrayBuffer(res);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
map(f) {
|
|
316
|
+
return new ArrayBuffer(this.items.map(i => f(i)));
|
|
317
|
+
}
|
|
318
|
+
mapPromise(f) {
|
|
319
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
const res = [];
|
|
321
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
322
|
+
res.push(yield f(this.items[i]));
|
|
323
|
+
}
|
|
324
|
+
return new ArrayBuffer(res);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
mapPromiseAll(f) {
|
|
328
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
return new ArrayBuffer(yield Promise.all(this.items.map(i => f(i))));
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
flatMapPromiseAll(f) {
|
|
333
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
return (yield this.mapPromiseAll(f)).flatten();
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
flatten() {
|
|
338
|
+
const res = [];
|
|
339
|
+
this.items.forEach(i => {
|
|
340
|
+
if (i instanceof ArrayBuffer) {
|
|
341
|
+
res.push(...i.items);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
res.push(i);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
return new ArrayBuffer(res);
|
|
348
|
+
}
|
|
349
|
+
toMap(mapper) {
|
|
350
|
+
return index_1.HashMap.of(...this.map(mapper).toArray);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
exports.ArrayBuffer = ArrayBuffer;
|
package/dist/hashmap.d.ts
CHANGED
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
import { Option } from './
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare type Tuple2<K, V> = [K, V];
|
|
6
|
-
export declare class HashMap<K, V> extends ArrayIterable<Tuple2<K, V>, HashMap<K, V>> {
|
|
7
|
-
private readonly map;
|
|
1
|
+
import { mutable, Option } from './index';
|
|
2
|
+
import { AbstractMap, Tuple2 } from './abstract-map';
|
|
3
|
+
export declare class HashMap<K, V> extends AbstractMap<K, V, HashMap<K, V>> {
|
|
4
|
+
protected readonly map: Map<K, V>;
|
|
8
5
|
protected fromArray(array: Tuple2<K, V>[]): HashMap<K, V>;
|
|
9
|
-
constructor(map: Map<K, V>);
|
|
6
|
+
protected constructor(map: Map<K, V>);
|
|
10
7
|
static of<K, V>(...values: Tuple2<K, V>[]): HashMap<K, V>;
|
|
8
|
+
static from<K, V>(values: Iterable<Tuple2<K, V>>): HashMap<K, V>;
|
|
11
9
|
static empty: HashMap<any, any>;
|
|
12
|
-
get size(): number;
|
|
13
|
-
get isEmpty(): boolean;
|
|
14
|
-
get(key: K): Option<V>;
|
|
15
|
-
getOrElse(key: K, defaultValue: () => V): V;
|
|
16
|
-
getOrElseValue(key: K, defaultValue: V): V;
|
|
17
|
-
get keySet(): HashSet<K>;
|
|
18
|
-
get keyIterator(): IterableIterator<K>;
|
|
19
|
-
get keys(): Collection<K>;
|
|
20
|
-
get values(): Collection<V>;
|
|
21
|
-
get valueIterator(): IterableIterator<V>;
|
|
22
|
-
get entries(): Collection<Tuple2<K, V>>;
|
|
23
|
-
get entriesIterator(): IterableIterator<Tuple2<K, V>>;
|
|
24
10
|
appendedAll(map: HashMap<K, V>): HashMap<K, V>;
|
|
11
|
+
appended(key: K, value: V): HashMap<K, V>;
|
|
12
|
+
updated(key: K, value: V): HashMap<K, V>;
|
|
13
|
+
removed(key: K): HashMap<K, V>;
|
|
14
|
+
removedAll(keys: Iterable<K>): HashMap<K, V>;
|
|
25
15
|
concat(map: HashMap<K, V>): HashMap<K, V>;
|
|
26
16
|
set(key: K, value: V): HashMap<K, V>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
updated(key: K, value: V): HashMap<K, V>;
|
|
30
|
-
get toCollection(): Collection<Tuple2<K, V>>;
|
|
31
|
-
get toMap(): Map<K, V>;
|
|
32
|
-
get toArray(): Array<Tuple2<K, V>>;
|
|
17
|
+
updatedWith(key: K): (remappingFunction: (maybeValue: Option<V>) => Option<V>) => HashMap<K, V>;
|
|
18
|
+
get toMutable(): mutable.HashMap<K, V>;
|
|
33
19
|
}
|
package/dist/hashmap.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HashMap = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const array_iterable_1 = require("./array-iterable");
|
|
8
|
-
class HashMap extends array_iterable_1.ArrayIterable {
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const abstract_map_1 = require("./abstract-map");
|
|
6
|
+
class HashMap extends abstract_map_1.AbstractMap {
|
|
9
7
|
constructor(map) {
|
|
10
|
-
super();
|
|
8
|
+
super(map);
|
|
11
9
|
this.map = map;
|
|
12
10
|
}
|
|
13
11
|
fromArray(array) {
|
|
@@ -16,44 +14,29 @@ class HashMap extends array_iterable_1.ArrayIterable {
|
|
|
16
14
|
static of(...values) {
|
|
17
15
|
return new HashMap(new Map(values));
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
return
|
|
17
|
+
static from(values) {
|
|
18
|
+
return HashMap.of(...Array.from(values));
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
return this.map
|
|
24
|
-
}
|
|
25
|
-
get(key) {
|
|
26
|
-
return option_1.option(this.map.get(key));
|
|
27
|
-
}
|
|
28
|
-
getOrElse(key, defaultValue) {
|
|
29
|
-
return this.get(key).getOrElse(defaultValue);
|
|
30
|
-
}
|
|
31
|
-
getOrElseValue(key, defaultValue) {
|
|
32
|
-
return this.get(key).getOrElseValue(defaultValue);
|
|
33
|
-
}
|
|
34
|
-
get keySet() {
|
|
35
|
-
return hashset_1.HashSet.of(...Array.from(this.map.keys()));
|
|
36
|
-
}
|
|
37
|
-
get keyIterator() {
|
|
38
|
-
return this.map.keys();
|
|
39
|
-
}
|
|
40
|
-
get keys() {
|
|
41
|
-
return new collection_1.Collection(Array.from(this.map.keys()));
|
|
42
|
-
}
|
|
43
|
-
get values() {
|
|
44
|
-
return new collection_1.Collection(Array.from(this.map.values()));
|
|
20
|
+
appendedAll(map) {
|
|
21
|
+
return this.concat(map);
|
|
45
22
|
}
|
|
46
|
-
|
|
47
|
-
return this.
|
|
23
|
+
appended(key, value) {
|
|
24
|
+
return this.set(key, value);
|
|
48
25
|
}
|
|
49
|
-
|
|
50
|
-
return
|
|
26
|
+
updated(key, value) {
|
|
27
|
+
return this.set(key, value);
|
|
51
28
|
}
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
removed(key) {
|
|
30
|
+
const next = new Map(this.map);
|
|
31
|
+
next.delete(key);
|
|
32
|
+
return new HashMap(next);
|
|
54
33
|
}
|
|
55
|
-
|
|
56
|
-
|
|
34
|
+
removedAll(keys) {
|
|
35
|
+
const next = new Map(this.map);
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
next.delete(key);
|
|
38
|
+
}
|
|
39
|
+
return new HashMap(next);
|
|
57
40
|
}
|
|
58
41
|
concat(map) {
|
|
59
42
|
const mergedMap = new Map([
|
|
@@ -67,25 +50,23 @@ class HashMap extends array_iterable_1.ArrayIterable {
|
|
|
67
50
|
next.set(key, value);
|
|
68
51
|
return new HashMap(new Map(next));
|
|
69
52
|
}
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
get toArray() {
|
|
88
|
-
return Array.from(this.map.entries());
|
|
53
|
+
updatedWith(key) {
|
|
54
|
+
const previousValue = this.get(key);
|
|
55
|
+
return (remappingFunction) => {
|
|
56
|
+
const nextValue = remappingFunction(previousValue);
|
|
57
|
+
if (previousValue.isEmpty && nextValue.isEmpty) {
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
else if (previousValue.isDefined && nextValue.isEmpty) {
|
|
61
|
+
return this.removed(key);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return this.updated(key, nextValue.get);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
get toMutable() {
|
|
69
|
+
return index_1.mutable.HashMap.of(...Array.from(this.map.entries()));
|
|
89
70
|
}
|
|
90
71
|
}
|
|
91
72
|
exports.HashMap = HashMap;
|
package/dist/hashset.d.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import { Collection } from './collection';
|
|
2
|
-
import { ArrayIterable } from './array-iterable';
|
|
3
1
|
import { HashMap } from './hashmap';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor(items: Set<T>);
|
|
2
|
+
import { AbstractSet } from './abstract-set';
|
|
3
|
+
import * as mutable from './mutable/hashset';
|
|
4
|
+
export declare class HashSet<T> extends AbstractSet<T, HashSet<T>> {
|
|
5
|
+
protected constructor(items: Set<T>);
|
|
8
6
|
static empty: HashSet<any>;
|
|
9
7
|
static of<T>(...items: T[]): HashSet<T>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
static from<T>(elements: Iterable<T>): HashSet<T>;
|
|
9
|
+
protected fromArray(array: T[]): HashSet<T>;
|
|
10
|
+
toMap<K, V>(mapper: (item: T) => [K, V]): HashMap<K, V>;
|
|
13
11
|
map<B>(f: (item: T) => B): HashSet<B>;
|
|
14
12
|
flatMap<B>(f: (item: T) => HashSet<B>): HashSet<B>;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
get size(): number;
|
|
18
|
-
concat(other: ArrayIterable<T, any>): HashSet<T>;
|
|
19
|
-
union(other: ArrayIterable<T, any>): HashSet<T>;
|
|
13
|
+
concat(that: Iterable<T>): HashSet<T>;
|
|
14
|
+
union(other: Iterable<T>): HashSet<T>;
|
|
20
15
|
appended(item: T): HashSet<T>;
|
|
21
|
-
appendedAll(other:
|
|
16
|
+
appendedAll(other: Iterable<T>): HashSet<T>;
|
|
22
17
|
removed(item: T): HashSet<T>;
|
|
23
|
-
removedAll(other:
|
|
18
|
+
removedAll(other: Iterable<T>): HashSet<T>;
|
|
24
19
|
intersect(other: HashSet<T>): HashSet<T>;
|
|
25
|
-
|
|
20
|
+
get toMutable(): mutable.HashSet<T>;
|
|
26
21
|
}
|
package/dist/hashset.js
CHANGED
|
@@ -1,59 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HashSet = void 0;
|
|
4
|
-
const
|
|
5
|
-
const array_iterable_1 = require("./array-iterable");
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
6
5
|
const hashmap_1 = require("./hashmap");
|
|
7
|
-
|
|
6
|
+
const abstract_set_1 = require("./abstract-set");
|
|
7
|
+
const mutable = tslib_1.__importStar(require("./mutable/hashset"));
|
|
8
|
+
class HashSet extends abstract_set_1.AbstractSet {
|
|
8
9
|
constructor(items) {
|
|
9
|
-
super();
|
|
10
|
-
this.items = items;
|
|
11
|
-
}
|
|
12
|
-
fromArray(array) {
|
|
13
|
-
return HashSet.of(...array);
|
|
10
|
+
super(items);
|
|
14
11
|
}
|
|
15
12
|
static of(...items) {
|
|
16
13
|
return new HashSet(new Set(items));
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
return new
|
|
15
|
+
static from(elements) {
|
|
16
|
+
return new HashSet(new Set(elements));
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
return
|
|
18
|
+
fromArray(array) {
|
|
19
|
+
return HashSet.of(...array);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
return
|
|
21
|
+
toMap(mapper) {
|
|
22
|
+
return hashmap_1.HashMap.of(...this.map(mapper).toArray);
|
|
26
23
|
}
|
|
27
24
|
map(f) {
|
|
28
25
|
return HashSet.of(...Array.from(this.items).map(i => f(i)));
|
|
29
26
|
}
|
|
30
27
|
flatMap(f) {
|
|
31
|
-
|
|
32
|
-
this.items.forEach(i =>
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
return res;
|
|
36
|
-
}
|
|
37
|
-
get toArray() {
|
|
38
|
-
return Array.from(this.items.keys());
|
|
39
|
-
}
|
|
40
|
-
get isEmpty() {
|
|
41
|
-
return this.items.size <= 0;
|
|
42
|
-
}
|
|
43
|
-
get size() {
|
|
44
|
-
return this.items.size;
|
|
28
|
+
const res = new Set();
|
|
29
|
+
this.items.forEach(i => f(i).foreach(e => res.add(e)));
|
|
30
|
+
return new HashSet(res);
|
|
45
31
|
}
|
|
46
|
-
concat(
|
|
47
|
-
return this.appendedAll(
|
|
32
|
+
concat(that) {
|
|
33
|
+
return this.appendedAll(that);
|
|
48
34
|
}
|
|
49
35
|
union(other) {
|
|
50
36
|
return this.concat(other);
|
|
51
37
|
}
|
|
52
38
|
appended(item) {
|
|
53
|
-
return
|
|
39
|
+
return this.fromArray(this.toArray.concat([item]));
|
|
54
40
|
}
|
|
55
41
|
appendedAll(other) {
|
|
56
|
-
|
|
42
|
+
const res = Array.from(this.items);
|
|
43
|
+
res.push(...Array.from(other));
|
|
44
|
+
return this.fromArray(res);
|
|
57
45
|
}
|
|
58
46
|
removed(item) {
|
|
59
47
|
const res = new Set(Array.from(this.items));
|
|
@@ -62,14 +50,16 @@ class HashSet extends array_iterable_1.ArrayIterable {
|
|
|
62
50
|
}
|
|
63
51
|
removedAll(other) {
|
|
64
52
|
const res = new Set(Array.from(this.items));
|
|
65
|
-
|
|
53
|
+
for (const element of other) {
|
|
54
|
+
res.delete(element);
|
|
55
|
+
}
|
|
66
56
|
return new HashSet(res);
|
|
67
57
|
}
|
|
68
58
|
intersect(other) {
|
|
69
59
|
return this.filter(x => other.contains(x));
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
return
|
|
61
|
+
get toMutable() {
|
|
62
|
+
return mutable.HashSet.of(...this.items);
|
|
73
63
|
}
|
|
74
64
|
}
|
|
75
65
|
exports.HashSet = HashSet;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mutable = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
tslib_1.__exportStar(require("./collection"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./either"), exports);
|
|
@@ -8,3 +9,5 @@ tslib_1.__exportStar(require("./hashset"), exports);
|
|
|
8
9
|
tslib_1.__exportStar(require("./option"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./try"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./util"), exports);
|
|
12
|
+
const mutable = tslib_1.__importStar(require("./mutable"));
|
|
13
|
+
exports.mutable = mutable;
|