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
@@ -0,0 +1,177 @@
1
+ import {AbstractSet} from '../abstract-set';
2
+ import * as immutable from '../hashset';
3
+
4
+ export class HashSet<T> extends AbstractSet<T, HashSet<T>> {
5
+
6
+ constructor(items: Set<T> = new Set()) {
7
+ super(items);
8
+ }
9
+
10
+ static of<T>(...items: T[]): HashSet<T> {
11
+ return new HashSet<T>(new Set(items));
12
+ }
13
+
14
+ static from<T>(values: Iterable<T>): HashSet<T> {
15
+ return HashSet.of(...Array.from(values));
16
+ }
17
+
18
+ protected fromArray(array: T[]): HashSet<T> {
19
+ return HashSet.of(...array);
20
+ }
21
+
22
+ /**
23
+ * Adds an element to this set
24
+ * @param elem element to add
25
+ * @return true if the element wasn't already contained in the set
26
+ */
27
+ add(elem: T): boolean {
28
+ const res = this.items.has(elem);
29
+ if (!res) {
30
+ this.items.add(elem);
31
+ return true;
32
+ } else {
33
+ return !res;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Adds all elements produced by an Iterable to this set.
39
+ *
40
+ * @param xs the Iterable producing the elements to add.
41
+ * @return the set itself.
42
+ */
43
+ addAll(xs: Iterable<T>): this {
44
+ for (const x of xs) {
45
+ this.items.add(x);
46
+ }
47
+ return this;
48
+ }
49
+
50
+ /**
51
+ * Removes all elements produced by an iterator from this set.
52
+ *
53
+ * @param xs the iterator producing the elements to remove.
54
+ * @return the set itself
55
+ */
56
+ subtractAll(xs: Iterable<T>): this {
57
+ for (const x of xs) {
58
+ this.items.delete(x);
59
+ }
60
+ return this;
61
+ }
62
+
63
+ /**
64
+ * Removes an element from this set.
65
+ *
66
+ * @param elem the element to be removed
67
+ * @return true if this set contained the element before it was removed
68
+ */
69
+ remove(elem: T) : boolean {
70
+ const res = this.items.has(elem);
71
+ if (res) {
72
+ this.items.delete(elem);
73
+ return true;
74
+ } else {
75
+ return res;
76
+ }
77
+
78
+ }
79
+
80
+
81
+ /**
82
+ * Removes all elements from the set for which do not satisfy a predicate.
83
+ * @param p the predicate used to test elements. Only elements for
84
+ * which `p` returns `true` are retained in the set; all others
85
+ * are removed.
86
+ */
87
+ filterInPlace(p: (item: T) => boolean): this {
88
+ if (this.nonEmpty) {
89
+ const arr = this.toArray;
90
+ for (const t of arr) {
91
+ if (!p(t)) {
92
+ this.remove(t);
93
+ }
94
+ }
95
+ }
96
+ return this;
97
+ }
98
+
99
+
100
+ /** Clears the set's contents. After this operation, the
101
+ * set is empty.
102
+ */
103
+ clear(): void {
104
+ this.items.clear();
105
+ }
106
+
107
+ /**
108
+ * Adds a single element to this set.
109
+ *
110
+ * @param elem the element to add.
111
+ * @return the $coll itself
112
+ */
113
+ addOne(elem: T): this {
114
+ this.add(elem);
115
+ return this;
116
+ }
117
+
118
+
119
+ /** Removes a single element from this set.
120
+ *
121
+ * @param elem the element to remove.
122
+ * @return the set itself
123
+ */
124
+ subtractOne(elem: T): this {
125
+ this.remove(elem);
126
+ return this;
127
+ }
128
+
129
+ /**
130
+ * Creates a new $coll by adding all elements contained in another collection to this $coll, omitting duplicates.
131
+ *
132
+ * This method takes a collection of elements and adds all elements, omitting duplicates, into $coll.
133
+ *
134
+ * Example:
135
+ * {{{
136
+ * scala> val a = Set(1, 2) concat Set(2, 3)
137
+ * a: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
138
+ * }}}
139
+ *
140
+ * @param that the collection containing the elements to add.
141
+ * @return a new $coll with the given elements added, omitting duplicates.
142
+ */
143
+ concat(that: Iterable<T>): HashSet<T> {
144
+ const newSet = new Set<T>([...this.items, ...that]);
145
+ return new HashSet<T>(newSet);
146
+ }
147
+
148
+ /**
149
+ * Computes the intersection between this set and another set.
150
+ *
151
+ * @param that the set to intersect with.
152
+ * @return a new set consisting of all elements that are both in this
153
+ * set and in the given set `that`.
154
+ */
155
+ intersect(that: AbstractSet<T, any>): HashSet<T> {
156
+ return this.filter(x => that.contains(x));
157
+ }
158
+
159
+ /** Computes the union between of set and another set.
160
+ *
161
+ * @param that the set to form the union with.
162
+ * @return a new set consisting of all elements that are in this
163
+ * set or in the given set `that`.
164
+ */
165
+ union(that: AbstractSet<T, any>): HashSet<T> {
166
+ return this.concat(that);
167
+ }
168
+
169
+ /**
170
+ * Creates the immutable HashMap with the contents from this HashMap.
171
+ * @return immutable HashMap
172
+ */
173
+ get toImmutable(): immutable.HashSet<T> {
174
+ return immutable.HashSet.of(...this.items);
175
+ }
176
+
177
+ }
package/src/mutable.ts ADDED
@@ -0,0 +1,3 @@
1
+ export {ArrayBuffer} from './collection';
2
+ export {HashMap} from './mutable/hashmap';
3
+ export {HashSet} from './mutable/hashset';
package/src/option.ts CHANGED
@@ -79,7 +79,7 @@ export abstract class Option<A> extends ArrayIterable<A, Option<A>> implements M
79
79
  if (this.isEmpty) {
80
80
  return Promise.resolve(none);
81
81
  } else {
82
- return option(await f(this.get));
82
+ return option<B>(await f(this.get));
83
83
  }
84
84
  }
85
85
 
@@ -102,7 +102,7 @@ export abstract class Option<A> extends ArrayIterable<A, Option<A>> implements M
102
102
  }
103
103
 
104
104
  forall(p: (_: A) => boolean): boolean {
105
- return this.isEmpty ? false : p(this.get);
105
+ return this.isEmpty ? true : p(this.get);
106
106
  }
107
107
 
108
108
 
package/src/try.ts CHANGED
@@ -57,7 +57,7 @@ export abstract class TryLike<T> implements Mappable<T>{
57
57
  f(e);
58
58
  return this;
59
59
  } catch (ex) {
60
- return failure(ex);
60
+ return failure(ex as Error);
61
61
  }
62
62
  }
63
63
  });
@@ -120,7 +120,7 @@ export class Success<T> extends TryLike<T> {
120
120
  try {
121
121
  return f(this.result);
122
122
  } catch (e) {
123
- return failure(e);
123
+ return failure(e as Error);
124
124
  }
125
125
  }
126
126
 
@@ -132,7 +132,7 @@ export class Success<T> extends TryLike<T> {
132
132
  return failure(new Error('Predicate does not hold for ' + this.result));
133
133
  }
134
134
  } catch (e) {
135
- return failure(e);
135
+ return failure(e as Error);
136
136
  }
137
137
  }
138
138
 
@@ -144,7 +144,7 @@ export class Success<T> extends TryLike<T> {
144
144
  try {
145
145
  return fb(this.result);
146
146
  } catch (e) {
147
- return fa(e);
147
+ return fa(e as Error);
148
148
  }
149
149
  }
150
150
 
@@ -202,7 +202,7 @@ export class Failure extends TryLike<any> {
202
202
  try {
203
203
  return value();
204
204
  } catch (e) {
205
- return failure(e);
205
+ return failure(e as Error);
206
206
  }
207
207
  }
208
208
 
@@ -230,7 +230,7 @@ export class Failure extends TryLike<any> {
230
230
  try {
231
231
  return success(f(this.error));
232
232
  } catch (ex) {
233
- return failure(ex);
233
+ return failure(ex as Error);
234
234
  }
235
235
  }
236
236
 
@@ -242,7 +242,7 @@ export class Failure extends TryLike<any> {
242
242
  try {
243
243
  return f(this.error);
244
244
  } catch (ex) {
245
- return failure(ex);
245
+ return failure(ex as Error);
246
246
  }
247
247
  }
248
248
 
@@ -254,7 +254,7 @@ export function Try<T>(block: () => T): TryLike<T> {
254
254
  try {
255
255
  return new Success(block());
256
256
  } catch (e) {
257
- return new Failure(e);
257
+ return new Failure(e as Error);
258
258
  }
259
259
  }
260
260
 
@@ -265,7 +265,7 @@ export namespace Try {
265
265
  .then(res => new Success(res))
266
266
  .catch(e => new Failure(e));
267
267
  } catch (e) {
268
- return Promise.resolve(new Failure(e));
268
+ return Promise.resolve(new Failure(e as Error));
269
269
  }
270
270
  }
271
271
  }