@everyonesoftware/common 2.0.0 → 3.0.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 (59) hide show
  1. package/.github/workflows/publish.yml +54 -36
  2. package/package.json +6 -2
  3. package/sources/asyncIterator.ts +436 -436
  4. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
  5. package/sources/asyncResult.ts +95 -95
  6. package/sources/byteList.ts +201 -201
  7. package/sources/byteListStream.ts +120 -120
  8. package/sources/byteReadStream.ts +23 -23
  9. package/sources/byteWriteStream.ts +15 -15
  10. package/sources/characterList.ts +194 -194
  11. package/sources/characterListStream.ts +150 -150
  12. package/sources/characterReadStream.ts +80 -80
  13. package/sources/characterReadStreamIterator.ts +127 -127
  14. package/sources/concatenateIterable.ts +118 -118
  15. package/sources/concatenateIterator.ts +164 -164
  16. package/sources/currentProcess.ts +157 -157
  17. package/sources/dateTime.ts +129 -129
  18. package/sources/depthFirstSearch.ts +229 -229
  19. package/sources/flatMapIterable.ts +103 -103
  20. package/sources/flatMapIterator.ts +151 -151
  21. package/sources/generator.ts +250 -250
  22. package/sources/index.ts +1 -1
  23. package/sources/iterator.ts +480 -480
  24. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
  25. package/sources/javascriptSetSet.ts +133 -133
  26. package/sources/listQueue.ts +61 -61
  27. package/sources/listStack.ts +61 -61
  28. package/sources/luxonDateTime.ts +108 -108
  29. package/sources/mapAsyncIterator.ts +140 -140
  30. package/sources/mutableMap.ts +291 -291
  31. package/sources/node.ts +36 -36
  32. package/sources/promiseAsyncResult.ts +173 -173
  33. package/sources/queue.ts +48 -48
  34. package/sources/recreationDotGovClient.ts +258 -258
  35. package/sources/searchControl.ts +41 -41
  36. package/sources/set.ts +243 -243
  37. package/sources/skipAsyncIterator.ts +144 -144
  38. package/sources/stack.ts +47 -47
  39. package/sources/syncResult.ts +299 -299
  40. package/sources/takeAsyncIterator.ts +140 -140
  41. package/sources/whereAsyncIterator.ts +142 -142
  42. package/sources/wonderlandTrailClient.ts +1502 -1502
  43. package/tests/assertTestTests.ts +74 -74
  44. package/tests/byteListStreamTests.ts +389 -389
  45. package/tests/byteListTests.ts +26 -26
  46. package/tests/characterListStreamTests.ts +390 -390
  47. package/tests/characterListTests.ts +249 -249
  48. package/tests/dateTimeTests.ts +29 -29
  49. package/tests/depthFirstSearchTests.ts +105 -105
  50. package/tests/generatorTests.ts +85 -85
  51. package/tests/mutableMapTests.ts +153 -153
  52. package/tests/promiseAsyncResultTests.ts +687 -687
  53. package/tests/queueTests.ts +28 -28
  54. package/tests/recreationDotGovClientTests.ts +190 -190
  55. package/tests/setTests.ts +139 -139
  56. package/tests/stackTests.ts +65 -65
  57. package/tests/syncResultTests.ts +1250 -1250
  58. package/tests/wonderlandTrailClientTests.ts +451 -451
  59. package/tsup.config.ts +12 -12
@@ -1,292 +1,292 @@
1
- import { EqualFunctions } from "./equalFunctions";
2
- import { Iterable } from "./iterable";
3
- import { Iterator } from "./iterator";
4
- import { JavascriptIterable, JavascriptIterator } from "./javascript";
5
- import { JavascriptMapMap } from "./javascriptMapMap";
6
- import { NotFoundError } from "./notFoundError";
7
- import { PreCondition } from "./preCondition";
8
- import { SyncResult } from "./syncResult";
9
- import { ToStringFunctions } from "./toStringFunctions";
10
- import { hasFunction, Type } from "./types";
11
- import { isMap, Map, MapEntry } from "./map";
12
-
13
- /**
14
- * Get whether the provided value is {@link Map}.
15
- * @param value The value to check.
16
- */
17
- export function isMutableMap(value: unknown): value is MutableMap<unknown, unknown>
18
- {
19
- return value instanceof MutableMap ||
20
- (
21
- isMap(value) &&
22
- hasFunction(value, "set", 2) &&
23
- hasFunction(value, "getOrSet", 2)
24
- );
25
- }
26
-
27
- /**
28
- * A type that maps {@link TKey} values to {@link TValue} values.
29
- */
30
- export abstract class MutableMap<TKey, TValue> implements Map<TKey, TValue>
31
- {
32
- /**
33
- * Create a new instance of the default {@link Map} implementation.
34
- */
35
- public static create<TKey, TValue>(): MutableMap<TKey, TValue>
36
- {
37
- return JavascriptMapMap.create();
38
- }
39
-
40
- /**
41
- * Iterate over the entries in this {@link MutableMap}.
42
- */
43
- public abstract iterate(): Iterator<MapEntry<TKey, TValue>>;
44
-
45
- public any(): SyncResult<boolean>
46
- {
47
- return MutableMap.any(this);
48
- }
49
-
50
- public static any<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<boolean>
51
- {
52
- return Map.any(map);
53
- }
54
-
55
- public toArray(): SyncResult<MapEntry<TKey, TValue>[]>
56
- {
57
- return MutableMap.toArray(this);
58
- }
59
-
60
- public static toArray<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<MapEntry<TKey,TValue>[]>
61
- {
62
- return Map.toArray(map);
63
- }
64
-
65
- public equals(right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
66
- {
67
- return MutableMap.equals(this, right, equalFunctions);
68
- }
69
-
70
- public static equals<TKey, TValue>(left: MutableMap<TKey, TValue>, right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
71
- {
72
- return Map.equals(left, right, equalFunctions);
73
- }
74
-
75
- /**
76
- * Get the {@link String} representation of this {@link MutableMap}.
77
- */
78
- public toString(toStringFunctions?: ToStringFunctions): string
79
- {
80
- return MutableMap.toString(this, toStringFunctions);
81
- }
82
-
83
- /**
84
- * Get the {@link String} representation of the provided {@link MutableMap}.
85
- */
86
- public static toString<TKey, TValue>(map: MutableMap<TKey, TValue>, toStringFunctions?: ToStringFunctions): string
87
- {
88
- return Map.toString(map, toStringFunctions);
89
- }
90
-
91
- public concatenate(...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
92
- {
93
- return MutableMap.concatenate(this, ...toConcatenate);
94
- }
95
-
96
- public static concatenate<TKey,TValue>(map: MutableMap<TKey,TValue>, ...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
97
- {
98
- return Map.concatenate(map, ...toConcatenate);
99
- }
100
-
101
- public map<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
102
- {
103
- return MutableMap.map(this, mapping);
104
- }
105
-
106
- public static map<TKey,TValue,TOutput>(map: MutableMap<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
107
- {
108
- return Map.map(map, mapping);
109
- }
110
-
111
- public flatMap<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
112
- {
113
- return MutableMap.flatMap(this, mapping);
114
- }
115
-
116
- public static flatMap<TKey,TValue,TOutput>(map: MutableMap<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
117
- {
118
- return Map.flatMap(map, mapping);
119
- }
120
-
121
- public where(condition: (value: MapEntry<TKey, TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey, TValue>>
122
- {
123
- return MutableMap.where(this, condition);
124
- }
125
-
126
- public static where<TKey,TValue>(map: MutableMap<TKey,TValue>, condition: (value: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey,TValue>>
127
- {
128
- return Map.where(map, condition);
129
- }
130
-
131
- public instanceOf<T extends MapEntry<TKey, TValue>>(typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
132
- {
133
- return MutableMap.instanceOf(this, typeOrTypeCheck);
134
- }
135
-
136
- public static instanceOf<TKey,TValue,T extends MapEntry<TKey, TValue>>(map: MutableMap<TKey,TValue>, typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
137
- {
138
- return Map.instanceOf(map, typeOrTypeCheck);
139
- }
140
-
141
- public [Symbol.iterator](): JavascriptIterator<MapEntry<TKey, TValue>>
142
- {
143
- return MutableMap[Symbol.iterator](this);
144
- }
145
-
146
- public static [Symbol.iterator]<TKey,TValue>(map: MutableMap<TKey,TValue>): JavascriptIterator<MapEntry<TKey,TValue>>
147
- {
148
- return Map[Symbol.iterator](map);
149
- }
150
-
151
- /**
152
- * Get the number of entries in this {@link MutableMap}.
153
- */
154
- public getCount(): SyncResult<number>
155
- {
156
- return MutableMap.getCount(this);
157
- }
158
-
159
- public static getCount<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<number>
160
- {
161
- return Map.getCount(map);
162
- }
163
-
164
- public first(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
165
- {
166
- return MutableMap.first(this, condition);
167
- }
168
-
169
- public static first<TKey,TValue>(map: MutableMap<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
170
- {
171
- return Map.first(map, condition);
172
- }
173
-
174
- public last(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
175
- {
176
- return MutableMap.last(this, condition);
177
- }
178
-
179
- public static last<TKey,TValue>(map: MutableMap<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
180
- {
181
- return Map.last(map, condition);
182
- }
183
-
184
- /**
185
- * Get whether this {@link MutableMap} contains the provided key.
186
- * @param key The key to look for.
187
- */
188
- public abstract containsKey(key: TKey): SyncResult<boolean>;
189
-
190
- /**
191
- * Get the value associated with the provided key.
192
- * @param key The key of the value to get.
193
- */
194
- public abstract get(key: TKey): SyncResult<TValue>;
195
-
196
- /**
197
- * Set the key/value association in this {@link MutableMap}.
198
- * @param key The key associated with the value.
199
- * @param value The value associated with the key.
200
- */
201
- public abstract set(key: TKey, value: TValue): this;
202
-
203
- /**
204
- * Get the {@link TValue} associated with the provided {@link TKey}. If the provided
205
- * {@link TKey} doesn't exist in this {@link MutableMap}, then invoke the provided {@link valueCreator}
206
- * and associate the returned {@link TValue} with the provided {@link TKey}. Then return the new
207
- * {@link TValue}.
208
- * @param key The {@link TKey} of the {@link TValue} to get.
209
- * @param valueCreator The {@link Function} that will be invoked if the {@link TKey} doesn't
210
- * exist in this {@link MutableMap}.
211
- */
212
- public getOrSet(key: TKey, valueCreator: () => (TValue | SyncResult<TValue>)): SyncResult<TValue>
213
- {
214
- return MutableMap.getOrSet(this, key, valueCreator);
215
- }
216
-
217
- /**
218
- * Get the {@link TValue} associated with the provided {@link TKey}. If the provided
219
- * {@link TKey} doesn't exist in the {@link MutableMap}, then invoke the provided {@link valueCreator}
220
- * and associate the returned {@link TValue} with the provided {@link TKey}. Then return the new
221
- * {@link TValue}.
222
- * @param key The {@link TKey} of the {@link TValue} to get.
223
- * @param valueCreator The {@link Function} that will be invoked if the {@link TKey} doesn't
224
- * exist in this {@link MutableMap}.
225
- */
226
- public static getOrSet<TKey, TValue>(map: MutableMap<TKey, TValue>, key: TKey, valueCreator: () => (TValue | SyncResult<TValue>)): SyncResult<TValue>
227
- {
228
- PreCondition.assertNotUndefinedAndNotNull(map, "map");
229
- PreCondition.assertNotUndefinedAndNotNull(valueCreator, "valueCreator");
230
-
231
- return map.get(key)
232
- .catch(NotFoundError, () =>
233
- {
234
- const creatorResult: TValue | SyncResult<TValue> = valueCreator();
235
- const value: TValue = creatorResult instanceof SyncResult ? creatorResult.await() : creatorResult;
236
- map.set(key, value);
237
- return value;
238
- });
239
- }
240
-
241
- /**
242
- * Remove the provided {@link TKey} from this {@link MutableMap}. If the {@link TKey} doesn't exist in
243
- * this {@link MutableMap}, then return a {@link NotFoundError}. If the {@link TKey} does exist, then
244
- * return the {@link TValue} that was associated with it.
245
- * @param key The {@link TKey} to remove from this {@link MutableMap}.
246
- */
247
- public abstract remove(key: TKey): SyncResult<TValue>;
248
-
249
- /**
250
- * Iterate over the keys in this {@link MutableMap}.
251
- */
252
- public iterateKeys(): Iterator<TKey>
253
- {
254
- return MutableMap.iterateKeys(this);
255
- }
256
-
257
- /**
258
- * Iterate over the keys in the {@link MutableMap}.
259
- * @param map The map to iterate over.
260
- */
261
- public static iterateKeys<TKey, TValue>(map: MutableMap<TKey, TValue>): Iterator<TKey>
262
- {
263
- return Map.iterateKeys(map);
264
- }
265
-
266
- /**
267
- * Iterate over the values in this {@link MutableMap}.
268
- */
269
- public iterateValues(): Iterator<TValue>
270
- {
271
- return MutableMap.iterateValues(this);
272
- }
273
-
274
- /**
275
- * Iterate over the keys in the {@link MutableMap}.
276
- * @param map The map to iterate over.
277
- */
278
- public static iterateValues<TKey, TValue>(map: MutableMap<TKey, TValue>): Iterator<TValue>
279
- {
280
- return Map.iterateValues(map);
281
- }
282
-
283
- public contains(value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
284
- {
285
- return MutableMap.contains(this, value, equalFunctions);
286
- }
287
-
288
- public static contains<TKey,TValue>(map: MutableMap<TKey,TValue>, value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
289
- {
290
- return Map.contains(map, value, equalFunctions);
291
- }
1
+ import { EqualFunctions } from "./equalFunctions";
2
+ import { Iterable } from "./iterable";
3
+ import { Iterator } from "./iterator";
4
+ import { JavascriptIterable, JavascriptIterator } from "./javascript";
5
+ import { JavascriptMapMap } from "./javascriptMapMap";
6
+ import { NotFoundError } from "./notFoundError";
7
+ import { PreCondition } from "./preCondition";
8
+ import { SyncResult } from "./syncResult";
9
+ import { ToStringFunctions } from "./toStringFunctions";
10
+ import { hasFunction, Type } from "./types";
11
+ import { isMap, Map, MapEntry } from "./map";
12
+
13
+ /**
14
+ * Get whether the provided value is {@link Map}.
15
+ * @param value The value to check.
16
+ */
17
+ export function isMutableMap(value: unknown): value is MutableMap<unknown, unknown>
18
+ {
19
+ return value instanceof MutableMap ||
20
+ (
21
+ isMap(value) &&
22
+ hasFunction(value, "set", 2) &&
23
+ hasFunction(value, "getOrSet", 2)
24
+ );
25
+ }
26
+
27
+ /**
28
+ * A type that maps {@link TKey} values to {@link TValue} values.
29
+ */
30
+ export abstract class MutableMap<TKey, TValue> implements Map<TKey, TValue>
31
+ {
32
+ /**
33
+ * Create a new instance of the default {@link Map} implementation.
34
+ */
35
+ public static create<TKey, TValue>(): MutableMap<TKey, TValue>
36
+ {
37
+ return JavascriptMapMap.create();
38
+ }
39
+
40
+ /**
41
+ * Iterate over the entries in this {@link MutableMap}.
42
+ */
43
+ public abstract iterate(): Iterator<MapEntry<TKey, TValue>>;
44
+
45
+ public any(): SyncResult<boolean>
46
+ {
47
+ return MutableMap.any(this);
48
+ }
49
+
50
+ public static any<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<boolean>
51
+ {
52
+ return Map.any(map);
53
+ }
54
+
55
+ public toArray(): SyncResult<MapEntry<TKey, TValue>[]>
56
+ {
57
+ return MutableMap.toArray(this);
58
+ }
59
+
60
+ public static toArray<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<MapEntry<TKey,TValue>[]>
61
+ {
62
+ return Map.toArray(map);
63
+ }
64
+
65
+ public equals(right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
66
+ {
67
+ return MutableMap.equals(this, right, equalFunctions);
68
+ }
69
+
70
+ public static equals<TKey, TValue>(left: MutableMap<TKey, TValue>, right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
71
+ {
72
+ return Map.equals(left, right, equalFunctions);
73
+ }
74
+
75
+ /**
76
+ * Get the {@link String} representation of this {@link MutableMap}.
77
+ */
78
+ public toString(toStringFunctions?: ToStringFunctions): string
79
+ {
80
+ return MutableMap.toString(this, toStringFunctions);
81
+ }
82
+
83
+ /**
84
+ * Get the {@link String} representation of the provided {@link MutableMap}.
85
+ */
86
+ public static toString<TKey, TValue>(map: MutableMap<TKey, TValue>, toStringFunctions?: ToStringFunctions): string
87
+ {
88
+ return Map.toString(map, toStringFunctions);
89
+ }
90
+
91
+ public concatenate(...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
92
+ {
93
+ return MutableMap.concatenate(this, ...toConcatenate);
94
+ }
95
+
96
+ public static concatenate<TKey,TValue>(map: MutableMap<TKey,TValue>, ...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
97
+ {
98
+ return Map.concatenate(map, ...toConcatenate);
99
+ }
100
+
101
+ public map<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
102
+ {
103
+ return MutableMap.map(this, mapping);
104
+ }
105
+
106
+ public static map<TKey,TValue,TOutput>(map: MutableMap<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
107
+ {
108
+ return Map.map(map, mapping);
109
+ }
110
+
111
+ public flatMap<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
112
+ {
113
+ return MutableMap.flatMap(this, mapping);
114
+ }
115
+
116
+ public static flatMap<TKey,TValue,TOutput>(map: MutableMap<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
117
+ {
118
+ return Map.flatMap(map, mapping);
119
+ }
120
+
121
+ public where(condition: (value: MapEntry<TKey, TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey, TValue>>
122
+ {
123
+ return MutableMap.where(this, condition);
124
+ }
125
+
126
+ public static where<TKey,TValue>(map: MutableMap<TKey,TValue>, condition: (value: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey,TValue>>
127
+ {
128
+ return Map.where(map, condition);
129
+ }
130
+
131
+ public instanceOf<T extends MapEntry<TKey, TValue>>(typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
132
+ {
133
+ return MutableMap.instanceOf(this, typeOrTypeCheck);
134
+ }
135
+
136
+ public static instanceOf<TKey,TValue,T extends MapEntry<TKey, TValue>>(map: MutableMap<TKey,TValue>, typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
137
+ {
138
+ return Map.instanceOf(map, typeOrTypeCheck);
139
+ }
140
+
141
+ public [Symbol.iterator](): JavascriptIterator<MapEntry<TKey, TValue>>
142
+ {
143
+ return MutableMap[Symbol.iterator](this);
144
+ }
145
+
146
+ public static [Symbol.iterator]<TKey,TValue>(map: MutableMap<TKey,TValue>): JavascriptIterator<MapEntry<TKey,TValue>>
147
+ {
148
+ return Map[Symbol.iterator](map);
149
+ }
150
+
151
+ /**
152
+ * Get the number of entries in this {@link MutableMap}.
153
+ */
154
+ public getCount(): SyncResult<number>
155
+ {
156
+ return MutableMap.getCount(this);
157
+ }
158
+
159
+ public static getCount<TKey,TValue>(map: MutableMap<TKey,TValue>): SyncResult<number>
160
+ {
161
+ return Map.getCount(map);
162
+ }
163
+
164
+ public first(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
165
+ {
166
+ return MutableMap.first(this, condition);
167
+ }
168
+
169
+ public static first<TKey,TValue>(map: MutableMap<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
170
+ {
171
+ return Map.first(map, condition);
172
+ }
173
+
174
+ public last(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
175
+ {
176
+ return MutableMap.last(this, condition);
177
+ }
178
+
179
+ public static last<TKey,TValue>(map: MutableMap<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
180
+ {
181
+ return Map.last(map, condition);
182
+ }
183
+
184
+ /**
185
+ * Get whether this {@link MutableMap} contains the provided key.
186
+ * @param key The key to look for.
187
+ */
188
+ public abstract containsKey(key: TKey): SyncResult<boolean>;
189
+
190
+ /**
191
+ * Get the value associated with the provided key.
192
+ * @param key The key of the value to get.
193
+ */
194
+ public abstract get(key: TKey): SyncResult<TValue>;
195
+
196
+ /**
197
+ * Set the key/value association in this {@link MutableMap}.
198
+ * @param key The key associated with the value.
199
+ * @param value The value associated with the key.
200
+ */
201
+ public abstract set(key: TKey, value: TValue): this;
202
+
203
+ /**
204
+ * Get the {@link TValue} associated with the provided {@link TKey}. If the provided
205
+ * {@link TKey} doesn't exist in this {@link MutableMap}, then invoke the provided {@link valueCreator}
206
+ * and associate the returned {@link TValue} with the provided {@link TKey}. Then return the new
207
+ * {@link TValue}.
208
+ * @param key The {@link TKey} of the {@link TValue} to get.
209
+ * @param valueCreator The {@link Function} that will be invoked if the {@link TKey} doesn't
210
+ * exist in this {@link MutableMap}.
211
+ */
212
+ public getOrSet(key: TKey, valueCreator: () => (TValue | SyncResult<TValue>)): SyncResult<TValue>
213
+ {
214
+ return MutableMap.getOrSet(this, key, valueCreator);
215
+ }
216
+
217
+ /**
218
+ * Get the {@link TValue} associated with the provided {@link TKey}. If the provided
219
+ * {@link TKey} doesn't exist in the {@link MutableMap}, then invoke the provided {@link valueCreator}
220
+ * and associate the returned {@link TValue} with the provided {@link TKey}. Then return the new
221
+ * {@link TValue}.
222
+ * @param key The {@link TKey} of the {@link TValue} to get.
223
+ * @param valueCreator The {@link Function} that will be invoked if the {@link TKey} doesn't
224
+ * exist in this {@link MutableMap}.
225
+ */
226
+ public static getOrSet<TKey, TValue>(map: MutableMap<TKey, TValue>, key: TKey, valueCreator: () => (TValue | SyncResult<TValue>)): SyncResult<TValue>
227
+ {
228
+ PreCondition.assertNotUndefinedAndNotNull(map, "map");
229
+ PreCondition.assertNotUndefinedAndNotNull(valueCreator, "valueCreator");
230
+
231
+ return map.get(key)
232
+ .catch(NotFoundError, () =>
233
+ {
234
+ const creatorResult: TValue | SyncResult<TValue> = valueCreator();
235
+ const value: TValue = creatorResult instanceof SyncResult ? creatorResult.await() : creatorResult;
236
+ map.set(key, value);
237
+ return value;
238
+ });
239
+ }
240
+
241
+ /**
242
+ * Remove the provided {@link TKey} from this {@link MutableMap}. If the {@link TKey} doesn't exist in
243
+ * this {@link MutableMap}, then return a {@link NotFoundError}. If the {@link TKey} does exist, then
244
+ * return the {@link TValue} that was associated with it.
245
+ * @param key The {@link TKey} to remove from this {@link MutableMap}.
246
+ */
247
+ public abstract remove(key: TKey): SyncResult<TValue>;
248
+
249
+ /**
250
+ * Iterate over the keys in this {@link MutableMap}.
251
+ */
252
+ public iterateKeys(): Iterator<TKey>
253
+ {
254
+ return MutableMap.iterateKeys(this);
255
+ }
256
+
257
+ /**
258
+ * Iterate over the keys in the {@link MutableMap}.
259
+ * @param map The map to iterate over.
260
+ */
261
+ public static iterateKeys<TKey, TValue>(map: MutableMap<TKey, TValue>): Iterator<TKey>
262
+ {
263
+ return Map.iterateKeys(map);
264
+ }
265
+
266
+ /**
267
+ * Iterate over the values in this {@link MutableMap}.
268
+ */
269
+ public iterateValues(): Iterator<TValue>
270
+ {
271
+ return MutableMap.iterateValues(this);
272
+ }
273
+
274
+ /**
275
+ * Iterate over the keys in the {@link MutableMap}.
276
+ * @param map The map to iterate over.
277
+ */
278
+ public static iterateValues<TKey, TValue>(map: MutableMap<TKey, TValue>): Iterator<TValue>
279
+ {
280
+ return Map.iterateValues(map);
281
+ }
282
+
283
+ public contains(value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
284
+ {
285
+ return MutableMap.contains(this, value, equalFunctions);
286
+ }
287
+
288
+ public static contains<TKey,TValue>(map: MutableMap<TKey,TValue>, value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
289
+ {
290
+ return Map.contains(map, value, equalFunctions);
291
+ }
292
292
  }
package/sources/node.ts CHANGED
@@ -1,37 +1,37 @@
1
- import { Iterator } from "./iterator";
2
- import { PreCondition } from "./preCondition";
3
- import { Set } from "./set";
4
-
5
- export class Node<T>
6
- {
7
- private readonly value: T;
8
- private connectedNodes: Set<Node<T>>;
9
-
10
- private constructor(value: T)
11
- {
12
- this.value = value;
13
- this.connectedNodes = Set.create();
14
- }
15
-
16
- public static create<T>(value: T): Node<T>
17
- {
18
- return new Node<T>(value);
19
- }
20
-
21
- public getValue(): T
22
- {
23
- return this.value;
24
- }
25
-
26
- public iterateConnectedNodes(): Iterator<Node<T>>
27
- {
28
- return this.connectedNodes.iterate();
29
- }
30
-
31
- public addConnectedNode(node: Node<T>): void
32
- {
33
- PreCondition.assertNotUndefinedAndNotNull(node, "node");
34
-
35
- this.connectedNodes.add(node);
36
- }
1
+ import { Iterator } from "./iterator";
2
+ import { PreCondition } from "./preCondition";
3
+ import { Set } from "./set";
4
+
5
+ export class Node<T>
6
+ {
7
+ private readonly value: T;
8
+ private connectedNodes: Set<Node<T>>;
9
+
10
+ private constructor(value: T)
11
+ {
12
+ this.value = value;
13
+ this.connectedNodes = Set.create();
14
+ }
15
+
16
+ public static create<T>(value: T): Node<T>
17
+ {
18
+ return new Node<T>(value);
19
+ }
20
+
21
+ public getValue(): T
22
+ {
23
+ return this.value;
24
+ }
25
+
26
+ public iterateConnectedNodes(): Iterator<Node<T>>
27
+ {
28
+ return this.connectedNodes.iterate();
29
+ }
30
+
31
+ public addConnectedNode(node: Node<T>): void
32
+ {
33
+ PreCondition.assertNotUndefinedAndNotNull(node, "node");
34
+
35
+ this.connectedNodes.add(node);
36
+ }
37
37
  }