@everyonesoftware/common 1.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.
- package/.c8rc.json +12 -0
- package/.github/workflows/publish.yml +38 -0
- package/.mocharc.json +9 -0
- package/README.md +9 -0
- package/package.json +36 -0
- package/sources/assertMessageParameters.ts +22 -0
- package/sources/asyncIterator.ts +437 -0
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
- package/sources/asyncResult.ts +95 -0
- package/sources/basicDisposable.ts +57 -0
- package/sources/byteList.ts +202 -0
- package/sources/byteListStream.ts +121 -0
- package/sources/byteReadStream.ts +24 -0
- package/sources/byteWriteStream.ts +16 -0
- package/sources/bytes.ts +25 -0
- package/sources/characterList.ts +195 -0
- package/sources/characterListStream.ts +151 -0
- package/sources/characterReadStream.ts +81 -0
- package/sources/characterReadStreamIterator.ts +128 -0
- package/sources/characterWriteStream.ts +45 -0
- package/sources/commandLineParameter.ts +45 -0
- package/sources/commandLineParameters.ts +21 -0
- package/sources/comparable.ts +144 -0
- package/sources/comparer.ts +133 -0
- package/sources/comparison.ts +20 -0
- package/sources/concatenateIterable.ts +119 -0
- package/sources/concatenateIterator.ts +165 -0
- package/sources/condition.ts +329 -0
- package/sources/currentProcess.ts +158 -0
- package/sources/dateTime.ts +130 -0
- package/sources/depthFirstSearch.ts +230 -0
- package/sources/disposable.ts +31 -0
- package/sources/emptyError.ts +10 -0
- package/sources/english.ts +45 -0
- package/sources/equalFunctions.ts +123 -0
- package/sources/fetchHttpClient.ts +89 -0
- package/sources/fetchHttpResponse.ts +106 -0
- package/sources/flatMapIterable.ts +104 -0
- package/sources/flatMapIterator.ts +152 -0
- package/sources/generator.ts +251 -0
- package/sources/httpClient.ts +36 -0
- package/sources/httpHeader.ts +37 -0
- package/sources/httpHeaders.ts +216 -0
- package/sources/httpIncomingRequest.ts +30 -0
- package/sources/httpIncomingResponse.ts +19 -0
- package/sources/httpMethod.ts +164 -0
- package/sources/httpOutgoingRequest.ts +119 -0
- package/sources/httpOutgoingResponse.ts +113 -0
- package/sources/httpServer.ts +34 -0
- package/sources/inMemoryCharacterWriteStream.ts +78 -0
- package/sources/index.ts +101 -0
- package/sources/iterable.ts +345 -0
- package/sources/iterator.ts +481 -0
- package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
- package/sources/javascript.ts +59 -0
- package/sources/javascriptArrayList.ts +175 -0
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
- package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
- package/sources/javascriptMapMap.ts +143 -0
- package/sources/javascriptSetSet.ts +134 -0
- package/sources/list.ts +330 -0
- package/sources/listQueue.ts +62 -0
- package/sources/listStack.ts +62 -0
- package/sources/luxonDateTime.ts +109 -0
- package/sources/map.ts +302 -0
- package/sources/mapAsyncIterator.ts +141 -0
- package/sources/mapIterable.ts +105 -0
- package/sources/mapIterator.ts +145 -0
- package/sources/mutableCondition.ts +451 -0
- package/sources/mutableHttpHeaders.ts +204 -0
- package/sources/mutableMap.ts +292 -0
- package/sources/network.ts +18 -0
- package/sources/node.ts +37 -0
- package/sources/nodeJSCharacterWriteStream.ts +42 -0
- package/sources/nodeJSHttpIncomingRequest.ts +132 -0
- package/sources/nodeJSHttpServer.ts +134 -0
- package/sources/notFoundError.ts +12 -0
- package/sources/postCondition.ts +284 -0
- package/sources/postConditionError.ts +12 -0
- package/sources/preCondition.ts +284 -0
- package/sources/preConditionError.ts +12 -0
- package/sources/promiseAsyncResult.ts +174 -0
- package/sources/property.ts +63 -0
- package/sources/queue.ts +49 -0
- package/sources/realNetwork.ts +28 -0
- package/sources/recreationDotGovClient.ts +259 -0
- package/sources/searchControl.ts +42 -0
- package/sources/set.ts +244 -0
- package/sources/skipAsyncIterator.ts +145 -0
- package/sources/skipIterator.ts +155 -0
- package/sources/stack.ts +48 -0
- package/sources/stringComparer.ts +33 -0
- package/sources/stringIterator.ts +149 -0
- package/sources/strings.ts +322 -0
- package/sources/syncResult.ts +300 -0
- package/sources/takeAsyncIterator.ts +141 -0
- package/sources/takeIterator.ts +151 -0
- package/sources/toStringFunctions.ts +185 -0
- package/sources/types.ts +371 -0
- package/sources/whereAsyncIterator.ts +143 -0
- package/sources/whereIterable.ts +108 -0
- package/sources/whereIterator.ts +157 -0
- package/sources/wonderlandTrailClient.ts +1503 -0
- package/tests/assertTest.ts +113 -0
- package/tests/assertTestTests.ts +75 -0
- package/tests/basicTestSkip.ts +51 -0
- package/tests/byteListStreamTests.ts +390 -0
- package/tests/byteListTests.ts +27 -0
- package/tests/bytesTests.ts +43 -0
- package/tests/characterListStreamTests.ts +391 -0
- package/tests/characterListTests.ts +250 -0
- package/tests/characterWriteStreamTests.ts +12 -0
- package/tests/comparerTests.ts +92 -0
- package/tests/conditionTests.ts +877 -0
- package/tests/consoleTestRunner.ts +404 -0
- package/tests/consoleTestRunnerTests.ts +651 -0
- package/tests/dateTimeTests.ts +30 -0
- package/tests/depthFirstSearchTests.ts +106 -0
- package/tests/disposableTests.ts +121 -0
- package/tests/englishTests.ts +103 -0
- package/tests/equalFunctionsTests.ts +223 -0
- package/tests/failedTest.ts +43 -0
- package/tests/fetchHttpClientTests.ts +33 -0
- package/tests/generatorTests.ts +86 -0
- package/tests/httpClientTests.ts +18 -0
- package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
- package/tests/iterableTests.ts +141 -0
- package/tests/iteratorTests.ts +1086 -0
- package/tests/javascriptMapMapTests.ts +21 -0
- package/tests/listTests.ts +338 -0
- package/tests/mapIteratorTests.ts +55 -0
- package/tests/mapTests.ts +104 -0
- package/tests/mutableConditionTests.ts +273 -0
- package/tests/mutableMapTests.ts +154 -0
- package/tests/nodeJSHttpServerTests.ts +75 -0
- package/tests/notFoundErrorTests.ts +24 -0
- package/tests/postConditionErrorTests.ts +24 -0
- package/tests/preConditionErrorTests.ts +24 -0
- package/tests/promiseAsyncResultTests.ts +688 -0
- package/tests/propertyTests.ts +63 -0
- package/tests/queueTests.ts +29 -0
- package/tests/recreationDotGovClientTests.ts +191 -0
- package/tests/setTests.ts +140 -0
- package/tests/skippedTest.ts +39 -0
- package/tests/stackTests.ts +66 -0
- package/tests/stringComparerTests.ts +60 -0
- package/tests/stringIteratorTests.ts +156 -0
- package/tests/stringsTests.ts +516 -0
- package/tests/syncResultTests.ts +1251 -0
- package/tests/test.ts +228 -0
- package/tests/testAction.ts +75 -0
- package/tests/testActionTests.ts +93 -0
- package/tests/testFailureTests.ts +12 -0
- package/tests/testRunner.ts +267 -0
- package/tests/testRunnerTests.ts +895 -0
- package/tests/testSkip.ts +34 -0
- package/tests/tests.ts +103 -0
- package/tests/toStringFunctionsTests.ts +55 -0
- package/tests/typesTests.ts +257 -0
- package/tests/whereIteratorTests.ts +77 -0
- package/tests/wonderlandTrailClientTests.ts +452 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +13 -0
package/sources/map.ts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { Comparer } from "./comparer";
|
|
2
|
+
import { EqualFunctions } from "./equalFunctions";
|
|
3
|
+
import { Iterable } from "./iterable";
|
|
4
|
+
import { Iterator } from "./iterator";
|
|
5
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
6
|
+
import { MutableMap } from "./mutableMap";
|
|
7
|
+
import { NotFoundError } from "./notFoundError";
|
|
8
|
+
import { PreCondition } from "./preCondition";
|
|
9
|
+
import { join } from "./strings";
|
|
10
|
+
import { SyncResult } from "./syncResult";
|
|
11
|
+
import { ToStringFunctions } from "./toStringFunctions";
|
|
12
|
+
import { hasFunction, isUndefinedOrNull, Type } from "./types";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get whether the provided value is {@link Map}.
|
|
16
|
+
* @param value The value to check.
|
|
17
|
+
*/
|
|
18
|
+
export function isMap(value: unknown): value is Map<unknown, unknown>
|
|
19
|
+
{
|
|
20
|
+
return value instanceof Map ||
|
|
21
|
+
(
|
|
22
|
+
hasFunction(value, "containsKey", 1) &&
|
|
23
|
+
hasFunction(value, "get", 1) &&
|
|
24
|
+
hasFunction(value, "set", 2) &&
|
|
25
|
+
hasFunction(value, "iterateKeys", 0) &&
|
|
26
|
+
hasFunction(value, "iterateValues", 0)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An entry within a {@link Map}.
|
|
32
|
+
*/
|
|
33
|
+
export interface MapEntry<TKey, TValue>
|
|
34
|
+
{
|
|
35
|
+
/**
|
|
36
|
+
* The key of the {@link MapEntry}.
|
|
37
|
+
*/
|
|
38
|
+
readonly key: TKey,
|
|
39
|
+
/**
|
|
40
|
+
* The value of the {@link MapEntry}.
|
|
41
|
+
*/
|
|
42
|
+
readonly value: TValue,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A type that maps {@link TKey} values to {@link TValue} values.
|
|
47
|
+
*/
|
|
48
|
+
export abstract class Map<TKey, TValue> implements Iterable<MapEntry<TKey, TValue>>
|
|
49
|
+
{
|
|
50
|
+
/**
|
|
51
|
+
* Create a new instance of the default {@link MutableMap} implementation.
|
|
52
|
+
*/
|
|
53
|
+
public static create<TKey, TValue>(): MutableMap<TKey, TValue>
|
|
54
|
+
{
|
|
55
|
+
return MutableMap.create();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Iterate over the entries in this {@link Map}.
|
|
60
|
+
*/
|
|
61
|
+
public abstract iterate(): Iterator<MapEntry<TKey, TValue>>;
|
|
62
|
+
|
|
63
|
+
public any(): SyncResult<boolean>
|
|
64
|
+
{
|
|
65
|
+
return Map.any(this);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public static any<TKey,TValue>(map: Map<TKey,TValue>): SyncResult<boolean>
|
|
69
|
+
{
|
|
70
|
+
return Iterable.any(map);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public toArray(): SyncResult<MapEntry<TKey, TValue>[]>
|
|
74
|
+
{
|
|
75
|
+
return Map.toArray(this);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public static toArray<TKey,TValue>(map: Map<TKey,TValue>): SyncResult<MapEntry<TKey,TValue>[]>
|
|
79
|
+
{
|
|
80
|
+
return Iterable.toArray(map);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public equals(right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
84
|
+
{
|
|
85
|
+
return Map.equals(this, right, equalFunctions);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public static equals<TKey, TValue>(left: Map<TKey, TValue>, right: Iterable<MapEntry<TKey, TValue>>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
89
|
+
{
|
|
90
|
+
return SyncResult.create(() =>
|
|
91
|
+
{
|
|
92
|
+
if (isUndefinedOrNull(equalFunctions))
|
|
93
|
+
{
|
|
94
|
+
equalFunctions = EqualFunctions.create();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let result: boolean | undefined = Comparer.equalSameUndefinedNull(left, right);
|
|
98
|
+
if (result === undefined)
|
|
99
|
+
{
|
|
100
|
+
result = true;
|
|
101
|
+
for (const entry of right)
|
|
102
|
+
{
|
|
103
|
+
result = left.get(entry.key)
|
|
104
|
+
.then((value: TValue) => equalFunctions!.areEqual(value, entry.value).await())
|
|
105
|
+
.catch(() => false)
|
|
106
|
+
.await();
|
|
107
|
+
if (result === false)
|
|
108
|
+
{
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get the {@link String} representation of this {@link Map}.
|
|
119
|
+
*/
|
|
120
|
+
public toString(toStringFunctions?: ToStringFunctions): string
|
|
121
|
+
{
|
|
122
|
+
return Map.toString(this, toStringFunctions);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the {@link String} representation of the provided {@link Map}.
|
|
127
|
+
*/
|
|
128
|
+
public static toString<TKey, TValue>(map: Map<TKey, TValue>, toStringFunctions?: ToStringFunctions): string
|
|
129
|
+
{
|
|
130
|
+
PreCondition.assertNotUndefinedAndNotNull(map, "iterable");
|
|
131
|
+
|
|
132
|
+
if (!toStringFunctions)
|
|
133
|
+
{
|
|
134
|
+
toStringFunctions = ToStringFunctions.create();
|
|
135
|
+
}
|
|
136
|
+
return `{${join(",", map.map((entry: MapEntry<unknown, unknown>) => `${toStringFunctions.toString(entry.key)}:${toStringFunctions.toString(entry.value)}`))}}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public concatenate(...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
|
|
140
|
+
{
|
|
141
|
+
return Map.concatenate(this, ...toConcatenate);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public static concatenate<TKey,TValue>(map: Map<TKey,TValue>, ...toConcatenate: JavascriptIterable<MapEntry<TKey, TValue>>[]): Iterable<MapEntry<TKey, TValue>>
|
|
145
|
+
{
|
|
146
|
+
return Iterable.concatenate(map, ...toConcatenate);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public map<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
|
|
150
|
+
{
|
|
151
|
+
return Map.map(this, mapping);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public static map<TKey,TValue,TOutput>(map: Map<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => (TOutput | SyncResult<TOutput>)): Iterable<TOutput>
|
|
155
|
+
{
|
|
156
|
+
return Iterable.map(map, mapping);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public flatMap<TOutput>(mapping: (value: MapEntry<TKey, TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
|
|
160
|
+
{
|
|
161
|
+
return Map.flatMap(this, mapping);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public static flatMap<TKey,TValue,TOutput>(map: Map<TKey,TValue>, mapping: (value: MapEntry<TKey,TValue>) => JavascriptIterable<TOutput>): Iterable<TOutput>
|
|
165
|
+
{
|
|
166
|
+
return Iterable.flatMap(map, mapping);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public where(condition: (value: MapEntry<TKey, TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey, TValue>>
|
|
170
|
+
{
|
|
171
|
+
return Map.where(this, condition);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public static where<TKey,TValue>(map: Map<TKey,TValue>, condition: (value: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): Iterable<MapEntry<TKey,TValue>>
|
|
175
|
+
{
|
|
176
|
+
return Iterable.where(map, condition);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public instanceOf<T extends MapEntry<TKey, TValue>>(typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
|
|
180
|
+
{
|
|
181
|
+
return Map.instanceOf(this, typeOrTypeCheck);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public static instanceOf<TKey,TValue,T extends MapEntry<TKey, TValue>>(map: Map<TKey,TValue>, typeOrTypeCheck: Type<T> | ((value: MapEntry<TKey, TValue>) => value is T)): Iterable<T>
|
|
185
|
+
{
|
|
186
|
+
return Iterable.instanceOf(map, typeOrTypeCheck);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public [Symbol.iterator](): JavascriptIterator<MapEntry<TKey, TValue>>
|
|
190
|
+
{
|
|
191
|
+
return Map[Symbol.iterator](this);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public static [Symbol.iterator]<TKey,TValue>(map: Map<TKey,TValue>): JavascriptIterator<MapEntry<TKey,TValue>>
|
|
195
|
+
{
|
|
196
|
+
return Iterable[Symbol.iterator](map);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the number of entries in this {@link Map}.
|
|
201
|
+
*/
|
|
202
|
+
public getCount(): SyncResult<number>
|
|
203
|
+
{
|
|
204
|
+
return Map.getCount(this);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public static getCount<TKey,TValue>(map: Map<TKey,TValue>): SyncResult<number>
|
|
208
|
+
{
|
|
209
|
+
return Iterable.getCount(map);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public first(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
|
|
213
|
+
{
|
|
214
|
+
return Map.first(this, condition);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public static first<TKey,TValue>(map: Map<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
|
|
218
|
+
{
|
|
219
|
+
return Iterable.first(map, condition);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public last(condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
|
|
223
|
+
{
|
|
224
|
+
return Map.last(this, condition);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
public static last<TKey,TValue>(map: Map<TKey,TValue>, condition?: (entry: MapEntry<TKey,TValue>) => (boolean | SyncResult<boolean>)): SyncResult<MapEntry<TKey, TValue>>
|
|
228
|
+
{
|
|
229
|
+
return Iterable.last(map, condition);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Get whether this {@link Map} contains the provided key.
|
|
234
|
+
* @param key The key to look for.
|
|
235
|
+
*/
|
|
236
|
+
public abstract containsKey(key: TKey): SyncResult<boolean>;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get the value associated with the provided key.
|
|
240
|
+
* @param key The key of the value to get.
|
|
241
|
+
*/
|
|
242
|
+
public abstract get(key: TKey): SyncResult<TValue>;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Iterate over the keys in this {@link Map}.
|
|
246
|
+
*/
|
|
247
|
+
public iterateKeys(): Iterator<TKey>
|
|
248
|
+
{
|
|
249
|
+
return Map.iterateKeys(this);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Iterate over the keys in the {@link Map}.
|
|
254
|
+
* @param map The map to iterate over.
|
|
255
|
+
*/
|
|
256
|
+
public static iterateKeys<TKey, TValue>(map: Map<TKey, TValue>): Iterator<TKey>
|
|
257
|
+
{
|
|
258
|
+
PreCondition.assertNotUndefinedAndNotNull(map, "map");
|
|
259
|
+
|
|
260
|
+
return map.iterate().map((entry: MapEntry<TKey, TValue>) => entry.key);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Iterate over the values in this {@link Map}.
|
|
265
|
+
*/
|
|
266
|
+
public iterateValues(): Iterator<TValue>
|
|
267
|
+
{
|
|
268
|
+
return Map.iterateValues(this);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Iterate over the keys in the {@link Map}.
|
|
273
|
+
* @param map The map to iterate over.
|
|
274
|
+
*/
|
|
275
|
+
public static iterateValues<TKey, TValue>(map: Map<TKey, TValue>): Iterator<TValue>
|
|
276
|
+
{
|
|
277
|
+
PreCondition.assertNotUndefinedAndNotNull(map, "map");
|
|
278
|
+
|
|
279
|
+
return map.iterate().map((entry: MapEntry<TKey, TValue>) => entry.value);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public contains(value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
283
|
+
{
|
|
284
|
+
return Map.contains(this, value, equalFunctions);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public static contains<TKey,TValue>(map: Map<TKey,TValue>, value: MapEntry<TKey,TValue>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
288
|
+
{
|
|
289
|
+
return SyncResult.create(() =>
|
|
290
|
+
{
|
|
291
|
+
if (!equalFunctions)
|
|
292
|
+
{
|
|
293
|
+
equalFunctions = EqualFunctions.create();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return map.get(value.key)
|
|
297
|
+
.then(entryValue => equalFunctions!.areEqual(entryValue, value.value).await())
|
|
298
|
+
.catch(NotFoundError, () => false)
|
|
299
|
+
.await();
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { PreCondition } from "./preCondition";
|
|
2
|
+
import { Type } from "./types";
|
|
3
|
+
import { AsyncIterator } from "./asyncIterator";
|
|
4
|
+
import { PromiseAsyncResult } from "./promiseAsyncResult";
|
|
5
|
+
import { JavascriptAsyncIterator } from "./javascript";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An {@link AsyncIterator} that maps {@link TInput} values to {@link TOutput} values.
|
|
9
|
+
*/
|
|
10
|
+
export class MapAsyncIterator<TInput, TOutput> implements AsyncIterator<TOutput>
|
|
11
|
+
{
|
|
12
|
+
private readonly inputIterator: AsyncIterator<TInput>;
|
|
13
|
+
private readonly mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>);
|
|
14
|
+
private current: TOutput | undefined;
|
|
15
|
+
private started: boolean;
|
|
16
|
+
|
|
17
|
+
protected constructor(inputIterator: AsyncIterator<TInput>, mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>))
|
|
18
|
+
{
|
|
19
|
+
PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
|
|
20
|
+
PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
|
|
21
|
+
|
|
22
|
+
this.inputIterator = inputIterator;
|
|
23
|
+
this.mapping = mapping;
|
|
24
|
+
this.started = false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static create<TInput, TOutput>(inputIterator: AsyncIterator<TInput>, mapping: (value: TInput) => (TOutput | PromiseLike<TOutput>)): MapAsyncIterator<TInput, TOutput>
|
|
28
|
+
{
|
|
29
|
+
return new MapAsyncIterator(inputIterator, mapping);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public next(): PromiseAsyncResult<boolean>
|
|
33
|
+
{
|
|
34
|
+
return PromiseAsyncResult.create(async () =>
|
|
35
|
+
{
|
|
36
|
+
if (!this.hasStarted())
|
|
37
|
+
{
|
|
38
|
+
this.started = true;
|
|
39
|
+
await this.inputIterator.start();
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
{
|
|
43
|
+
await this.inputIterator.next();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const result: boolean = this.inputIterator.hasCurrent();
|
|
47
|
+
this.current = result
|
|
48
|
+
? await this.mapping(this.inputIterator.getCurrent())
|
|
49
|
+
: undefined;
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public hasStarted(): boolean
|
|
56
|
+
{
|
|
57
|
+
return this.started;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public hasCurrent(): boolean
|
|
61
|
+
{
|
|
62
|
+
return this.hasStarted() && this.inputIterator.hasCurrent();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public getCurrent(): TOutput
|
|
66
|
+
{
|
|
67
|
+
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
68
|
+
|
|
69
|
+
return this.current!;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public start(): PromiseAsyncResult<this>
|
|
73
|
+
{
|
|
74
|
+
return AsyncIterator.start<TOutput, this>(this);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public takeCurrent(): PromiseAsyncResult<TOutput>
|
|
78
|
+
{
|
|
79
|
+
return AsyncIterator.takeCurrent(this);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public any(): PromiseAsyncResult<boolean>
|
|
83
|
+
{
|
|
84
|
+
return AsyncIterator.any(this);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public getCount(): PromiseAsyncResult<number>
|
|
88
|
+
{
|
|
89
|
+
return AsyncIterator.getCount(this);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public toArray(): PromiseAsyncResult<TOutput[]>
|
|
93
|
+
{
|
|
94
|
+
return AsyncIterator.toArray(this);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | PromiseLike<TOutput2>)): AsyncIterator<TOutput2>
|
|
98
|
+
{
|
|
99
|
+
return AsyncIterator.map(this, mapping);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public [Symbol.asyncIterator](): JavascriptAsyncIterator<TOutput>
|
|
103
|
+
{
|
|
104
|
+
return AsyncIterator[Symbol.asyncIterator](this);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public first(condition?: (value: TOutput) => boolean): PromiseAsyncResult<TOutput>
|
|
108
|
+
{
|
|
109
|
+
return AsyncIterator.first(this, condition);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public last(): PromiseAsyncResult<TOutput>
|
|
113
|
+
{
|
|
114
|
+
return AsyncIterator.last(this);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public where(condition: (value: TOutput) => (boolean | PromiseLike<boolean>)): AsyncIterator<TOutput>
|
|
118
|
+
{
|
|
119
|
+
return AsyncIterator.where(this, condition);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public whereInstanceOf<U extends TOutput>(typeCheck: (value: TOutput) => value is U): AsyncIterator<U>
|
|
123
|
+
{
|
|
124
|
+
return AsyncIterator.whereInstanceOf(this, typeCheck);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public whereInstanceOfType<U extends TOutput>(type: Type<U>): AsyncIterator<U>
|
|
128
|
+
{
|
|
129
|
+
return AsyncIterator.whereInstanceOfType(this, type);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public take(maximumToTake: number): AsyncIterator<TOutput>
|
|
133
|
+
{
|
|
134
|
+
return AsyncIterator.take(this, maximumToTake);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public skip(maximumToSkip: number): AsyncIterator<TOutput>
|
|
138
|
+
{
|
|
139
|
+
return AsyncIterator.skip(this, maximumToSkip);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { EqualFunctions } from "./equalFunctions";
|
|
2
|
+
import { Iterable } from "./iterable";
|
|
3
|
+
import { Iterator } from "./iterator";
|
|
4
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
5
|
+
import { PreCondition } from "./preCondition";
|
|
6
|
+
import { SyncResult } from "./syncResult";
|
|
7
|
+
import { Type } from "./types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An {@link Iterable} that converts {@link TInput} values to {@link TOutput} values.
|
|
11
|
+
*/
|
|
12
|
+
export class MapIterable<TInput,TOutput> implements Iterable<TOutput>
|
|
13
|
+
{
|
|
14
|
+
private readonly innerIterable: Iterable<TInput>;
|
|
15
|
+
private readonly mapping: (value: TInput) => (TOutput | SyncResult<TOutput>);
|
|
16
|
+
|
|
17
|
+
protected constructor(innerIterable: Iterable<TInput>, mapping: (value: TInput) => (TOutput | SyncResult<TOutput>))
|
|
18
|
+
{
|
|
19
|
+
PreCondition.assertNotUndefinedAndNotNull(innerIterable, "innerIterable");
|
|
20
|
+
PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
|
|
21
|
+
|
|
22
|
+
this.innerIterable = innerIterable;
|
|
23
|
+
this.mapping = mapping;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static create<TInput,TOutput>(innerIterable: Iterable<TInput>, mapping: (value: TInput) => (TOutput | SyncResult<TOutput>)): MapIterable<TInput,TOutput>
|
|
27
|
+
{
|
|
28
|
+
return new MapIterable<TInput,TOutput>(innerIterable, mapping);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public iterate(): Iterator<TOutput>
|
|
32
|
+
{
|
|
33
|
+
return this.innerIterable.iterate().map(this.mapping);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public toArray(): SyncResult<TOutput[]>
|
|
37
|
+
{
|
|
38
|
+
return Iterable.toArray(this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public equals(right: Iterable<TOutput>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
42
|
+
{
|
|
43
|
+
return Iterable.equals(this, right, equalFunctions);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public toString(): string
|
|
47
|
+
{
|
|
48
|
+
return Iterable.toString(this);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public concatenate(...toConcatenate: JavascriptIterable<TOutput>[]): Iterable<TOutput>
|
|
52
|
+
{
|
|
53
|
+
return Iterable.concatenate(this, ...toConcatenate);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | SyncResult<TOutput2>)): Iterable<TOutput2>
|
|
57
|
+
{
|
|
58
|
+
return Iterable.map(this, mapping);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public flatMap<TOutput2>(mapping: (value: TOutput) => JavascriptIterable<TOutput2>): Iterable<TOutput2>
|
|
62
|
+
{
|
|
63
|
+
return Iterable.flatMap(this, mapping);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public where(condition: (value: TOutput) => boolean): Iterable<TOutput>
|
|
67
|
+
{
|
|
68
|
+
return Iterable.where(this, condition);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public instanceOf<TOutput2 extends TOutput>(typeOrTypeCheck: Type<TOutput2> | ((value: TOutput) => value is TOutput2)): Iterable<TOutput2>
|
|
72
|
+
{
|
|
73
|
+
return Iterable.instanceOf(this, typeOrTypeCheck);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public [Symbol.iterator](): JavascriptIterator<TOutput>
|
|
77
|
+
{
|
|
78
|
+
return Iterable[Symbol.iterator](this);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public any(): SyncResult<boolean>
|
|
82
|
+
{
|
|
83
|
+
return this.innerIterable.any();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getCount(): SyncResult<number>
|
|
87
|
+
{
|
|
88
|
+
return this.innerIterable.getCount();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public first(): SyncResult<TOutput>
|
|
92
|
+
{
|
|
93
|
+
return Iterable.first(this);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public last(): SyncResult<TOutput>
|
|
97
|
+
{
|
|
98
|
+
return Iterable.last(this);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public contains(value: TOutput, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
102
|
+
{
|
|
103
|
+
return Iterable.contains(this, value, equalFunctions);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Iterator } from "./iterator";
|
|
2
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
3
|
+
import { PreCondition } from "./preCondition";
|
|
4
|
+
import { SyncResult } from "./syncResult";
|
|
5
|
+
import { Type } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An {@link Iterator} that maps {@link TInput} values to {@link TOutput} values.
|
|
9
|
+
*/
|
|
10
|
+
export class MapIterator<TInput, TOutput> implements Iterator<TOutput>
|
|
11
|
+
{
|
|
12
|
+
private readonly inputIterator: Iterator<TInput>;
|
|
13
|
+
private readonly mapping: (value: TInput) => (TOutput | SyncResult<TOutput>);
|
|
14
|
+
private started: boolean;
|
|
15
|
+
|
|
16
|
+
protected constructor(inputIterator: Iterator<TInput>, mapping: (value: TInput) => (TOutput | SyncResult<TOutput>))
|
|
17
|
+
{
|
|
18
|
+
PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
|
|
19
|
+
PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
|
|
20
|
+
|
|
21
|
+
this.inputIterator = inputIterator;
|
|
22
|
+
this.mapping = mapping;
|
|
23
|
+
this.started = false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static create<TInput, TOutput>(inputIterator: Iterator<TInput>, mapping: (value: TInput) => (TOutput | SyncResult<TOutput>)): MapIterator<TInput, TOutput>
|
|
27
|
+
{
|
|
28
|
+
return new MapIterator(inputIterator, mapping);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public next(): SyncResult<boolean>
|
|
32
|
+
{
|
|
33
|
+
return SyncResult.create(() =>
|
|
34
|
+
{
|
|
35
|
+
if (!this.hasStarted())
|
|
36
|
+
{
|
|
37
|
+
this.started = true;
|
|
38
|
+
this.inputIterator.start();
|
|
39
|
+
}
|
|
40
|
+
else
|
|
41
|
+
{
|
|
42
|
+
this.inputIterator.next();
|
|
43
|
+
}
|
|
44
|
+
return this.inputIterator.hasCurrent();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public hasStarted(): boolean
|
|
49
|
+
{
|
|
50
|
+
return this.started;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public hasCurrent(): boolean
|
|
54
|
+
{
|
|
55
|
+
return this.hasStarted() && this.inputIterator.hasCurrent();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public getCurrent(): TOutput
|
|
59
|
+
{
|
|
60
|
+
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
61
|
+
|
|
62
|
+
const mappingResult: TOutput | SyncResult<TOutput> = this.mapping(this.inputIterator.getCurrent());
|
|
63
|
+
return mappingResult instanceof SyncResult ? mappingResult.await() : mappingResult;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public start(): SyncResult<this>
|
|
67
|
+
{
|
|
68
|
+
return Iterator.start<TOutput, this>(this);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public takeCurrent(): SyncResult<TOutput>
|
|
72
|
+
{
|
|
73
|
+
return Iterator.takeCurrent(this);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public any(): SyncResult<boolean>
|
|
77
|
+
{
|
|
78
|
+
return Iterator.any(this);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public getCount(): SyncResult<number>
|
|
82
|
+
{
|
|
83
|
+
return Iterator.getCount(this);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public toArray(): SyncResult<TOutput[]>
|
|
87
|
+
{
|
|
88
|
+
return Iterator.toArray(this);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public concatenate(toConcatenate: JavascriptIterable<TOutput>): Iterator<TOutput>
|
|
92
|
+
{
|
|
93
|
+
return Iterator.concatenate(this, toConcatenate);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | SyncResult<TOutput2>)): Iterator<TOutput2>
|
|
97
|
+
{
|
|
98
|
+
return Iterator.map(this, mapping);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public flatMap<TOutput2>(mapping: (value: TOutput) => JavascriptIterable<TOutput2>): Iterator<TOutput2>
|
|
102
|
+
{
|
|
103
|
+
return Iterator.flatMap(this, mapping);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public [Symbol.iterator](): JavascriptIterator<TOutput>
|
|
107
|
+
{
|
|
108
|
+
return Iterator[Symbol.iterator](this);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public first(condition?: (value: TOutput) => boolean): SyncResult<TOutput>
|
|
112
|
+
{
|
|
113
|
+
return Iterator.first(this, condition);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public last(): SyncResult<TOutput>
|
|
117
|
+
{
|
|
118
|
+
return Iterator.last(this);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public where(condition: (value: TOutput) => boolean): Iterator<TOutput>
|
|
122
|
+
{
|
|
123
|
+
return Iterator.where(this, condition);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public whereInstanceOf<U extends TOutput>(typeCheck: (value: TOutput) => value is U): Iterator<U>
|
|
127
|
+
{
|
|
128
|
+
return Iterator.whereInstanceOf(this, typeCheck);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public whereInstanceOfType<U extends TOutput>(type: Type<U>): Iterator<U>
|
|
132
|
+
{
|
|
133
|
+
return Iterator.whereInstanceOfType(this, type);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public take(maximumToTake: number): Iterator<TOutput>
|
|
137
|
+
{
|
|
138
|
+
return Iterator.take(this, maximumToTake);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public skip(maximumToSkip: number): Iterator<TOutput>
|
|
142
|
+
{
|
|
143
|
+
return Iterator.skip(this, maximumToSkip);
|
|
144
|
+
}
|
|
145
|
+
}
|