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.
Files changed (72) hide show
  1. package/README.md +82 -3
  2. package/coverage/clover.xml +937 -0
  3. package/coverage/coverage-final.json +15 -0
  4. package/coverage/lcov-report/array-iterable.ts.html +1709 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +79 -0
  7. package/coverage/lcov-report/collection.ts.html +1475 -0
  8. package/coverage/lcov-report/either.ts.html +1934 -0
  9. package/coverage/lcov-report/favicon.png +0 -0
  10. package/coverage/lcov-report/hashmap.ts.html +527 -0
  11. package/coverage/lcov-report/hashset.ts.html +392 -0
  12. package/coverage/lcov-report/index.html +126 -0
  13. package/coverage/lcov-report/index.ts.html +101 -0
  14. package/coverage/lcov-report/option.ts.html +758 -0
  15. package/coverage/lcov-report/prettify.css +1 -0
  16. package/coverage/lcov-report/prettify.js +2 -0
  17. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  18. package/coverage/lcov-report/sorter.js +170 -0
  19. package/coverage/lcov-report/src/abstract-map.ts.html +317 -0
  20. package/coverage/lcov-report/src/abstract-set.ts.html +200 -0
  21. package/coverage/lcov-report/src/array-iterable.ts.html +1751 -0
  22. package/coverage/lcov-report/src/collection.ts.html +1778 -0
  23. package/coverage/lcov-report/src/either.ts.html +1934 -0
  24. package/coverage/lcov-report/src/hashmap.ts.html +428 -0
  25. package/coverage/lcov-report/src/hashset.ts.html +482 -0
  26. package/coverage/lcov-report/src/index.html +276 -0
  27. package/coverage/lcov-report/src/index.ts.html +110 -0
  28. package/coverage/lcov-report/src/mutable/hashmap.ts.html +821 -0
  29. package/coverage/lcov-report/src/mutable/hashset.ts.html +611 -0
  30. package/coverage/lcov-report/src/mutable/index.html +126 -0
  31. package/coverage/lcov-report/src/mutable.ts.html +89 -0
  32. package/coverage/lcov-report/src/option.ts.html +758 -0
  33. package/coverage/lcov-report/src/try.ts.html +923 -0
  34. package/coverage/lcov-report/src/util.ts.html +518 -0
  35. package/coverage/lcov-report/try.ts.html +923 -0
  36. package/coverage/lcov-report/util.ts.html +518 -0
  37. package/coverage/lcov.info +2223 -0
  38. package/dist/abstract-map.d.ts +25 -0
  39. package/dist/abstract-map.js +62 -0
  40. package/dist/abstract-set.d.ts +13 -0
  41. package/dist/abstract-set.js +33 -0
  42. package/dist/array-iterable.d.ts +1 -3
  43. package/dist/array-iterable.js +21 -23
  44. package/dist/collection.d.ts +59 -20
  45. package/dist/collection.js +254 -62
  46. package/dist/hashmap.d.ts +12 -26
  47. package/dist/hashmap.js +39 -58
  48. package/dist/hashset.d.ts +12 -17
  49. package/dist/hashset.js +25 -35
  50. package/dist/index.d.ts +2 -0
  51. package/dist/index.js +3 -0
  52. package/dist/mutable/hashmap.d.ts +24 -0
  53. package/dist/mutable/hashmap.js +118 -0
  54. package/dist/mutable/hashset.d.ts +20 -0
  55. package/dist/mutable/hashset.js +88 -0
  56. package/dist/mutable.d.ts +3 -0
  57. package/dist/mutable.js +9 -0
  58. package/dist/option.js +1 -1
  59. package/package.json +12 -12
  60. package/src/abstract-map.ts +79 -0
  61. package/src/abstract-set.ts +40 -0
  62. package/src/array-iterable.ts +26 -12
  63. package/src/collection.ts +394 -85
  64. package/src/either.ts +2 -2
  65. package/src/hashmap.ts +74 -73
  66. package/src/hashset.ts +82 -42
  67. package/src/index.ts +3 -0
  68. package/src/mutable/hashmap.ts +247 -0
  69. package/src/mutable/hashset.ts +177 -0
  70. package/src/mutable.ts +3 -0
  71. package/src/option.ts +2 -2
  72. package/src/try.ts +9 -9
@@ -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 hashmap_1 = require("./hashmap");
6
- const hashset_1 = require("./hashset");
5
+ const index_1 = require("./index");
7
6
  const array_iterable_1 = require("./array-iterable");
8
- class Collection extends array_iterable_1.ArrayIterable {
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
- let res = [];
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
- res = res.concat(f(i).items);
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
- let res = [];
137
+ const res = [];
63
138
  for (let i = 0; i < this.items.length; i++) {
64
139
  const item = this.items[i];
65
- res = res.concat((yield f(item)).items);
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(idx) {
88
- return this.items[idx];
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 hashmap_1.HashMap.of(...this.map(mapper).toArray);
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 './option';
2
- import { Collection } from './collection';
3
- import { HashSet } from './hashset';
4
- import { ArrayIterable } from './array-iterable';
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
- remove(key: K): HashMap<K, V>;
28
- containsKey(key: K): boolean;
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 option_1 = require("./option");
5
- const collection_1 = require("./collection");
6
- const hashset_1 = require("./hashset");
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
- get size() {
20
- return this.map.size;
17
+ static from(values) {
18
+ return HashMap.of(...Array.from(values));
21
19
  }
22
- get isEmpty() {
23
- return this.map.size <= 0;
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
- get valueIterator() {
47
- return this.map.values();
23
+ appended(key, value) {
24
+ return this.set(key, value);
48
25
  }
49
- get entries() {
50
- return new collection_1.Collection(Array.from(this.map.entries()));
26
+ updated(key, value) {
27
+ return this.set(key, value);
51
28
  }
52
- get entriesIterator() {
53
- return this.map.entries();
29
+ removed(key) {
30
+ const next = new Map(this.map);
31
+ next.delete(key);
32
+ return new HashMap(next);
54
33
  }
55
- appendedAll(map) {
56
- return this.concat(map);
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
- remove(key) {
71
- const next = new Map(this.map);
72
- next.delete(key);
73
- return new HashMap(next);
74
- }
75
- containsKey(key) {
76
- return this.map.has(key);
77
- }
78
- updated(key, value) {
79
- return this.set(key, value);
80
- }
81
- get toCollection() {
82
- return new collection_1.Collection(Array.from(this.map.entries()));
83
- }
84
- get toMap() {
85
- return this.map;
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
- export declare class HashSet<T> extends ArrayIterable<T, HashSet<T>> {
5
- private readonly items;
6
- protected fromArray(array: T[]): HashSet<T>;
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
- get toCollection(): Collection<T>;
11
- get toSet(): Set<T>;
12
- contains(item: T): boolean;
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
- get toArray(): Array<T>;
16
- get isEmpty(): boolean;
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: ArrayIterable<T, any>): HashSet<T>;
16
+ appendedAll(other: Iterable<T>): HashSet<T>;
22
17
  removed(item: T): HashSet<T>;
23
- removedAll(other: HashSet<T>): HashSet<T>;
18
+ removedAll(other: Iterable<T>): HashSet<T>;
24
19
  intersect(other: HashSet<T>): HashSet<T>;
25
- toMap<K, V>(mapper: (item: T) => [K, V]): HashMap<K, V>;
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 collection_1 = require("./collection");
5
- const array_iterable_1 = require("./array-iterable");
4
+ const tslib_1 = require("tslib");
6
5
  const hashmap_1 = require("./hashmap");
7
- class HashSet extends array_iterable_1.ArrayIterable {
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
- get toCollection() {
19
- return new collection_1.Collection(Array.from(this.items.keys()));
15
+ static from(elements) {
16
+ return new HashSet(new Set(elements));
20
17
  }
21
- get toSet() {
22
- return this.items;
18
+ fromArray(array) {
19
+ return HashSet.of(...array);
23
20
  }
24
- contains(item) {
25
- return this.items.has(item);
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
- let res = HashSet.empty;
32
- this.items.forEach(i => {
33
- res = res.union(f(i));
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(other) {
47
- return this.appendedAll(other);
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 HashSet.of(...this.toArray.concat([item]));
39
+ return this.fromArray(this.toArray.concat([item]));
54
40
  }
55
41
  appendedAll(other) {
56
- return HashSet.of(...this.toArray.concat(other.toArray));
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
- other.foreach(i => res.delete(i));
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
- toMap(mapper) {
72
- return hashmap_1.HashMap.of(...this.map(mapper).toArray);
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
@@ -5,3 +5,5 @@ export * from './hashset';
5
5
  export * from './option';
6
6
  export * from './try';
7
7
  export * from './util';
8
+ import * as mutable from './mutable';
9
+ export { mutable };
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;