@everyonesoftware/common 3.0.0 → 5.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 (176) hide show
  1. package/outputs/chunk-AY3YWKOM.js +7741 -0
  2. package/outputs/chunk-AY3YWKOM.js.map +1 -0
  3. package/outputs/sources.cjs +9007 -0
  4. package/outputs/sources.cjs.map +1 -0
  5. package/outputs/sources.d.cts +4082 -0
  6. package/outputs/sources.d.ts +4082 -0
  7. package/outputs/sources.js +1370 -0
  8. package/outputs/sources.js.map +1 -0
  9. package/outputs/tests.cjs +17208 -0
  10. package/outputs/tests.cjs.map +1 -0
  11. package/outputs/tests.d.cts +3 -0
  12. package/outputs/tests.d.ts +3 -0
  13. package/outputs/tests.js +9798 -0
  14. package/outputs/tests.js.map +1 -0
  15. package/package.json +6 -1
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -54
  18. package/.mocharc.json +0 -9
  19. package/sources/assertMessageParameters.ts +0 -22
  20. package/sources/asyncIterator.ts +0 -437
  21. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
  22. package/sources/asyncResult.ts +0 -95
  23. package/sources/basicDisposable.ts +0 -57
  24. package/sources/byteList.ts +0 -202
  25. package/sources/byteListStream.ts +0 -121
  26. package/sources/byteReadStream.ts +0 -24
  27. package/sources/byteWriteStream.ts +0 -16
  28. package/sources/bytes.ts +0 -25
  29. package/sources/characterList.ts +0 -195
  30. package/sources/characterListStream.ts +0 -151
  31. package/sources/characterReadStream.ts +0 -81
  32. package/sources/characterReadStreamIterator.ts +0 -128
  33. package/sources/characterWriteStream.ts +0 -45
  34. package/sources/commandLineParameter.ts +0 -45
  35. package/sources/commandLineParameters.ts +0 -21
  36. package/sources/comparable.ts +0 -144
  37. package/sources/comparer.ts +0 -133
  38. package/sources/comparison.ts +0 -20
  39. package/sources/concatenateIterable.ts +0 -119
  40. package/sources/concatenateIterator.ts +0 -165
  41. package/sources/condition.ts +0 -329
  42. package/sources/currentProcess.ts +0 -158
  43. package/sources/dateTime.ts +0 -130
  44. package/sources/depthFirstSearch.ts +0 -230
  45. package/sources/disposable.ts +0 -31
  46. package/sources/emptyError.ts +0 -10
  47. package/sources/english.ts +0 -45
  48. package/sources/equalFunctions.ts +0 -123
  49. package/sources/fetchHttpClient.ts +0 -89
  50. package/sources/fetchHttpResponse.ts +0 -106
  51. package/sources/flatMapIterable.ts +0 -104
  52. package/sources/flatMapIterator.ts +0 -152
  53. package/sources/generator.ts +0 -251
  54. package/sources/httpClient.ts +0 -36
  55. package/sources/httpHeader.ts +0 -37
  56. package/sources/httpHeaders.ts +0 -216
  57. package/sources/httpIncomingRequest.ts +0 -30
  58. package/sources/httpIncomingResponse.ts +0 -19
  59. package/sources/httpMethod.ts +0 -164
  60. package/sources/httpOutgoingRequest.ts +0 -119
  61. package/sources/httpOutgoingResponse.ts +0 -113
  62. package/sources/httpServer.ts +0 -34
  63. package/sources/inMemoryCharacterWriteStream.ts +0 -78
  64. package/sources/index.ts +0 -101
  65. package/sources/iterable.ts +0 -345
  66. package/sources/iterator.ts +0 -481
  67. package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
  68. package/sources/javascript.ts +0 -59
  69. package/sources/javascriptArrayList.ts +0 -175
  70. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
  71. package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
  72. package/sources/javascriptMapMap.ts +0 -143
  73. package/sources/javascriptSetSet.ts +0 -134
  74. package/sources/list.ts +0 -330
  75. package/sources/listQueue.ts +0 -62
  76. package/sources/listStack.ts +0 -62
  77. package/sources/luxonDateTime.ts +0 -109
  78. package/sources/map.ts +0 -302
  79. package/sources/mapAsyncIterator.ts +0 -141
  80. package/sources/mapIterable.ts +0 -105
  81. package/sources/mapIterator.ts +0 -145
  82. package/sources/mutableCondition.ts +0 -451
  83. package/sources/mutableHttpHeaders.ts +0 -204
  84. package/sources/mutableMap.ts +0 -292
  85. package/sources/network.ts +0 -18
  86. package/sources/node.ts +0 -37
  87. package/sources/nodeJSCharacterWriteStream.ts +0 -42
  88. package/sources/nodeJSHttpIncomingRequest.ts +0 -132
  89. package/sources/nodeJSHttpServer.ts +0 -134
  90. package/sources/notFoundError.ts +0 -12
  91. package/sources/postCondition.ts +0 -284
  92. package/sources/postConditionError.ts +0 -12
  93. package/sources/preCondition.ts +0 -284
  94. package/sources/preConditionError.ts +0 -12
  95. package/sources/promiseAsyncResult.ts +0 -174
  96. package/sources/property.ts +0 -63
  97. package/sources/queue.ts +0 -49
  98. package/sources/realNetwork.ts +0 -28
  99. package/sources/recreationDotGovClient.ts +0 -259
  100. package/sources/searchControl.ts +0 -42
  101. package/sources/set.ts +0 -244
  102. package/sources/skipAsyncIterator.ts +0 -145
  103. package/sources/skipIterator.ts +0 -155
  104. package/sources/stack.ts +0 -48
  105. package/sources/stringComparer.ts +0 -33
  106. package/sources/stringIterator.ts +0 -149
  107. package/sources/strings.ts +0 -322
  108. package/sources/syncResult.ts +0 -300
  109. package/sources/takeAsyncIterator.ts +0 -141
  110. package/sources/takeIterator.ts +0 -151
  111. package/sources/toStringFunctions.ts +0 -185
  112. package/sources/types.ts +0 -371
  113. package/sources/whereAsyncIterator.ts +0 -143
  114. package/sources/whereIterable.ts +0 -108
  115. package/sources/whereIterator.ts +0 -157
  116. package/sources/wonderlandTrailClient.ts +0 -1503
  117. package/tests/assertTest.ts +0 -113
  118. package/tests/assertTestTests.ts +0 -75
  119. package/tests/basicTestSkip.ts +0 -51
  120. package/tests/byteListStreamTests.ts +0 -390
  121. package/tests/byteListTests.ts +0 -27
  122. package/tests/bytesTests.ts +0 -43
  123. package/tests/characterListStreamTests.ts +0 -391
  124. package/tests/characterListTests.ts +0 -250
  125. package/tests/characterWriteStreamTests.ts +0 -12
  126. package/tests/comparerTests.ts +0 -92
  127. package/tests/conditionTests.ts +0 -877
  128. package/tests/consoleTestRunner.ts +0 -404
  129. package/tests/consoleTestRunnerTests.ts +0 -651
  130. package/tests/dateTimeTests.ts +0 -30
  131. package/tests/depthFirstSearchTests.ts +0 -106
  132. package/tests/disposableTests.ts +0 -121
  133. package/tests/englishTests.ts +0 -103
  134. package/tests/equalFunctionsTests.ts +0 -223
  135. package/tests/failedTest.ts +0 -43
  136. package/tests/fetchHttpClientTests.ts +0 -33
  137. package/tests/generatorTests.ts +0 -86
  138. package/tests/httpClientTests.ts +0 -18
  139. package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
  140. package/tests/iterableTests.ts +0 -141
  141. package/tests/iteratorTests.ts +0 -1086
  142. package/tests/javascriptMapMapTests.ts +0 -21
  143. package/tests/listTests.ts +0 -338
  144. package/tests/mapIteratorTests.ts +0 -55
  145. package/tests/mapTests.ts +0 -104
  146. package/tests/mutableConditionTests.ts +0 -273
  147. package/tests/mutableMapTests.ts +0 -154
  148. package/tests/nodeJSHttpServerTests.ts +0 -75
  149. package/tests/notFoundErrorTests.ts +0 -24
  150. package/tests/postConditionErrorTests.ts +0 -24
  151. package/tests/preConditionErrorTests.ts +0 -24
  152. package/tests/promiseAsyncResultTests.ts +0 -688
  153. package/tests/propertyTests.ts +0 -63
  154. package/tests/queueTests.ts +0 -29
  155. package/tests/recreationDotGovClientTests.ts +0 -191
  156. package/tests/setTests.ts +0 -140
  157. package/tests/skippedTest.ts +0 -39
  158. package/tests/stackTests.ts +0 -66
  159. package/tests/stringComparerTests.ts +0 -60
  160. package/tests/stringIteratorTests.ts +0 -156
  161. package/tests/stringsTests.ts +0 -516
  162. package/tests/syncResultTests.ts +0 -1251
  163. package/tests/test.ts +0 -228
  164. package/tests/testAction.ts +0 -75
  165. package/tests/testActionTests.ts +0 -93
  166. package/tests/testFailureTests.ts +0 -12
  167. package/tests/testRunner.ts +0 -267
  168. package/tests/testRunnerTests.ts +0 -895
  169. package/tests/testSkip.ts +0 -34
  170. package/tests/tests.ts +0 -103
  171. package/tests/toStringFunctionsTests.ts +0 -55
  172. package/tests/typesTests.ts +0 -257
  173. package/tests/whereIteratorTests.ts +0 -77
  174. package/tests/wonderlandTrailClientTests.ts +0 -452
  175. package/tsconfig.json +0 -20
  176. package/tsup.config.ts +0 -13
package/sources/map.ts DELETED
@@ -1,302 +0,0 @@
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
- }
@@ -1,141 +0,0 @@
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
- }
@@ -1,105 +0,0 @@
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
- }
@@ -1,145 +0,0 @@
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
- }