@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
@@ -1,300 +0,0 @@
1
- import { PreCondition } from "./preCondition";
2
- import { PromiseAsyncResult } from "./promiseAsyncResult";
3
- import { instanceOfType, isPromise, isPromiseLike, isUndefinedOrNull, Type } from "./types";
4
- import { AsyncResult } from "./asyncResult";
5
-
6
- export class SyncResult<T> implements AsyncResult<T>
7
- {
8
- private value: T | undefined;
9
- private error: unknown | undefined;
10
-
11
- private constructor(value: T | undefined, error: unknown | undefined)
12
- {
13
- PreCondition.assertTrue(value === undefined || error === undefined, "value === undefined || error === undefined", "Either value or error must be undefined.");
14
-
15
- this.value = value;
16
- this.error = error;
17
- }
18
-
19
- public static create<T>(action: () => T): SyncResult<T>
20
- {
21
- PreCondition.assertNotUndefinedAndNotNull(action, "action");
22
-
23
- let value: T | undefined;
24
- let error: unknown | undefined;
25
- try
26
- {
27
- value = action();
28
- }
29
- catch (e)
30
- {
31
- error = e;
32
- }
33
- return new SyncResult(value, error);
34
- }
35
-
36
- public static value<T>(value: T): SyncResult<T>
37
- {
38
- return new SyncResult(value, undefined);
39
- }
40
-
41
- public static error<T>(error: unknown): SyncResult<T>
42
- {
43
- return new SyncResult<T>(undefined, error);
44
- }
45
-
46
- public await(): T
47
- {
48
- if (this.error)
49
- {
50
- throw this.error;
51
- }
52
- return this.value!;
53
- }
54
-
55
- public then<TResult1 = T, TResult2 = never>(onfullfilled?: ((value: T) => TResult1) | null, onrejected?: ((reason: unknown) => TResult2) | null): SyncResult<TResult1 | TResult2>;
56
- public then<TResult1 = T, TResult2 = never>(onfullfilled?: ((value: T) => (TResult1 | PromiseLike<TResult1>)) | null, onrejected?: ((reason: unknown) => (TResult2 | PromiseLike<TResult2>)) | null): SyncResult<TResult1 | TResult2>;
57
- then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => (TResult1 | PromiseLike<TResult1>)) | null, onrejected?: ((reason: unknown) => (TResult2 | PromiseLike<TResult2>)) | null): SyncResult<TResult1 | TResult2> | PromiseAsyncResult<TResult1 | TResult2>
58
- {
59
- let result: SyncResult<TResult1 | TResult2> | PromiseAsyncResult<TResult1 | TResult2>;
60
- if (this.error)
61
- {
62
- if (onrejected)
63
- {
64
- try
65
- {
66
- const onRejectedResult: TResult2 | PromiseLike<TResult2> = onrejected(this.error);
67
- if (onRejectedResult instanceof SyncResult || onRejectedResult instanceof PromiseAsyncResult)
68
- {
69
- result = onRejectedResult;
70
- }
71
- else if (isPromise<TResult2>(onRejectedResult))
72
- {
73
- result = PromiseAsyncResult.create(onRejectedResult);
74
- }
75
- else
76
- {
77
- result = SyncResult.value(onRejectedResult as TResult2);
78
- }
79
- }
80
- catch (error)
81
- {
82
- result = SyncResult.error(error);
83
- }
84
- }
85
- else
86
- {
87
- result = SyncResult.error<TResult2>(this.error);
88
- }
89
- }
90
- else
91
- {
92
- if (onfulfilled)
93
- {
94
- try
95
- {
96
- const onFullfilledResult: TResult1 | PromiseLike<TResult1> = onfulfilled(this.value!);
97
- if (onFullfilledResult instanceof SyncResult || onFullfilledResult instanceof PromiseAsyncResult)
98
- {
99
- result = onFullfilledResult;
100
- }
101
- else if (isPromise<TResult1>(onFullfilledResult))
102
- {
103
- result = PromiseAsyncResult.create(onFullfilledResult);
104
- }
105
- else
106
- {
107
- result = SyncResult.value(onFullfilledResult as TResult1);
108
- }
109
- }
110
- catch (error)
111
- {
112
- result = SyncResult.error(error);
113
- }
114
- }
115
- else
116
- {
117
- result = SyncResult.value<TResult1>(this.value as TResult1);
118
- }
119
- }
120
- return result;
121
- }
122
-
123
- public onValue(onValueFunction: (value: T) => void): SyncResult<T>;
124
- public onValue(onValueFunction: (value: T) => Promise<void>): PromiseAsyncResult<T>;
125
- onValue(onValueFunction: (value: T) => (void | Promise<void>)): SyncResult<T> | PromiseAsyncResult<T>
126
- {
127
- return this.then<T>((value: T) =>
128
- {
129
- let result: SyncResult<T> | PromiseAsyncResult<T>;
130
- try
131
- {
132
- const onValueFunctionResult: (void | Promise<void>) = onValueFunction(value);
133
- if (isPromise(onValueFunctionResult))
134
- {
135
- result = PromiseAsyncResult.create(onValueFunctionResult.then(() => value));
136
- }
137
- else
138
- {
139
- result = this;
140
- }
141
- }
142
- catch (error)
143
- {
144
- result = SyncResult.error(error);
145
- }
146
- return result;
147
- })
148
- }
149
-
150
- public catch<TResult = never>(onrejected: (reason: unknown) => TResult): SyncResult<T | TResult>;
151
- public catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): SyncResult<T | TResult> | PromiseAsyncResult<T | TResult>
152
- public catch<TError, TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => TResult): SyncResult<T | TResult>;
153
- public catch<TError, TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => PromiseLike<TResult>): PromiseAsyncResult<T | TResult>;
154
- catch<TResult = never>(errorTypeOrOnRejected?: Type<unknown> | ((reason: unknown) => TResult | PromiseLike<TResult>) | null, onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): SyncResult<T | TResult> | PromiseAsyncResult<T | TResult>
155
- {
156
- let errorType: Type<TypeError> | undefined;
157
- if (!isUndefinedOrNull(onrejected))
158
- {
159
- errorType = errorTypeOrOnRejected as Type<unknown>;
160
-
161
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
162
- }
163
- else
164
- {
165
- onrejected = errorTypeOrOnRejected as ((reason: any) => TResult | PromiseLike<TResult>) | null;
166
- }
167
- PreCondition.assertNotUndefinedAndNotNull(onrejected, "onrejected");
168
-
169
- let result: SyncResult<T | TResult> | PromiseAsyncResult<T | TResult> = this;
170
- if (this.error && (!errorType || instanceOfType(this.error, errorType)))
171
- {
172
- try
173
- {
174
- const onRejectedResult: TResult | PromiseLike<TResult> = onrejected(this.error);
175
- if (onRejectedResult instanceof SyncResult || onRejectedResult instanceof PromiseAsyncResult)
176
- {
177
- result = onRejectedResult;
178
- }
179
- else if (isPromise<TResult>(onRejectedResult))
180
- {
181
- result = PromiseAsyncResult.create(onRejectedResult);
182
- }
183
- else
184
- {
185
- result = SyncResult.value(onRejectedResult as TResult);
186
- }
187
- }
188
- catch (error)
189
- {
190
- result = SyncResult.error(error);
191
- }
192
- }
193
- return result;
194
- }
195
-
196
- public onError(onErrorFunction: (reason: unknown) => void): SyncResult<T>;
197
- public onError(onErrorFunction: (reason: unknown) => PromiseLike<void>): PromiseAsyncResult<T>;
198
- public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => void): SyncResult<T>;
199
- public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => PromiseLike<void>): PromiseAsyncResult<T>;
200
- onError(errorTypeOrOnErrorFunction: Type<unknown> | ((reason: unknown) => (void | PromiseLike<void>)), onErrorFunction?: (reason: unknown) => (void | PromiseLike<void>)): SyncResult<T> | PromiseAsyncResult<T>
201
- {
202
- let errorType: Type<TypeError> | undefined;
203
- if (!isUndefinedOrNull(onErrorFunction))
204
- {
205
- errorType = errorTypeOrOnErrorFunction as Type<unknown>;
206
-
207
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
208
- }
209
- else
210
- {
211
- onErrorFunction = errorTypeOrOnErrorFunction as ((reason: any) => void | PromiseLike<void>);
212
- }
213
- PreCondition.assertNotUndefinedAndNotNull(onErrorFunction, "onErrorFunction");
214
-
215
- let result: SyncResult<T> | PromiseAsyncResult<T> = this;
216
- if (this.error && (!errorType || instanceOfType(this.error, errorType)))
217
- {
218
- try
219
- {
220
- const onErrorResult: void | PromiseLike<void> = onErrorFunction(this.error);
221
- if (isPromise(onErrorResult))
222
- {
223
- result = PromiseAsyncResult.create(onErrorResult).then(() => this);
224
- }
225
- }
226
- catch (error)
227
- {
228
- result = SyncResult.error(error);
229
- }
230
- }
231
- return result;
232
- }
233
-
234
- public convertError(convertErrorFunction: (reason: unknown) => unknown): SyncResult<T>;
235
- public convertError(onErrorFunction: (reason: unknown) => PromiseLike<unknown>): PromiseAsyncResult<T>;
236
- public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => unknown): SyncResult<T>;
237
- public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => PromiseLike<unknown>): PromiseAsyncResult<T>;
238
- convertError(errorTypeOrConvertErrorFunction: Type<unknown> | ((reason: unknown) => (unknown | PromiseLike<unknown>)), convertErrorFunction?: (reason: unknown) => (unknown | PromiseLike<unknown>)): SyncResult<T> | PromiseAsyncResult<T>
239
- {
240
- let errorType: Type<TypeError> | undefined;
241
- if (!isUndefinedOrNull(convertErrorFunction))
242
- {
243
- errorType = errorTypeOrConvertErrorFunction as Type<unknown>;
244
-
245
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
246
- }
247
- else
248
- {
249
- convertErrorFunction = errorTypeOrConvertErrorFunction as ((reason: any) => void | PromiseLike<void>);
250
- }
251
- PreCondition.assertNotUndefinedAndNotNull(convertErrorFunction, "convertErrorFunction");
252
-
253
- let result: SyncResult<T> | PromiseAsyncResult<T> = this;
254
- if (this.error && (!errorType || instanceOfType(this.error, errorType)))
255
- {
256
- try
257
- {
258
- const convertErrorResult: unknown | PromiseLike<unknown> = convertErrorFunction(this.error);
259
- if (isPromise(convertErrorResult))
260
- {
261
- result = PromiseAsyncResult.error(convertErrorResult);
262
- }
263
- else
264
- {
265
- result = SyncResult.error(convertErrorResult);
266
- }
267
- }
268
- catch (error)
269
- {
270
- result = SyncResult.error(error);
271
- }
272
- }
273
- return result;
274
- }
275
-
276
- public finally(onfinally?: (() => void) | null): SyncResult<T>
277
- public finally(onfinally?: (() => Promise<void>) | null): PromiseAsyncResult<T>
278
- finally(onfinally?: (() => (void | Promise<void>)) | null | undefined): PromiseAsyncResult<T> | SyncResult<T>
279
- {
280
- let result: PromiseAsyncResult<T> | SyncResult<T> = this;
281
- if (onfinally)
282
- {
283
- try
284
- {
285
- const onfinallyResult: void | Promise<void> = onfinally();
286
- if (isPromiseLike(onfinallyResult))
287
- {
288
- result = PromiseAsyncResult.create(onfinallyResult).then(() => this);
289
- }
290
- }
291
- catch (error)
292
- {
293
- result = SyncResult.error(error);
294
- }
295
- }
296
- return result;
297
- }
298
-
299
- readonly [Symbol.toStringTag]: string = "SyncResult2";
300
- }
@@ -1,141 +0,0 @@
1
- import { AsyncIterator } from "./asyncIterator";
2
- import { PromiseAsyncResult } from "./promiseAsyncResult";
3
- import { JavascriptAsyncIterator } from "./javascript";
4
- import { PreCondition } from "./preCondition";
5
- import { Type } from "./types";
6
-
7
- /**
8
- * An {@link AsyncIterator} that iterates over a maximum number of values.
9
- */
10
- export class TakeAsyncIterator<T> implements AsyncIterator<T>
11
- {
12
- private readonly innerIterator: AsyncIterator<T>;
13
- private started: boolean;
14
- private readonly maximumToTake: number;
15
- private taken: number;
16
-
17
- private constructor(innerIterator: AsyncIterator<T>, maximumToTake: number)
18
- {
19
- PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
20
-
21
- this.innerIterator = innerIterator;
22
- this.started = false;
23
- this.maximumToTake = maximumToTake;
24
- this.taken = 0;
25
- }
26
-
27
- public static create<T>(innerIterator: AsyncIterator<T>, maximumToTake: number)
28
- {
29
- return new TakeAsyncIterator(innerIterator, maximumToTake);
30
- }
31
-
32
- public hasCurrent(): boolean
33
- {
34
- return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
35
- }
36
-
37
- public next(): PromiseAsyncResult<boolean>
38
- {
39
- return PromiseAsyncResult.create(async () =>
40
- {
41
- if (this.maximumToTake <= 0)
42
- {
43
- return false;
44
- }
45
- else if (!this.hasStarted())
46
- {
47
- this.started = true;
48
- await this.innerIterator.start();
49
- this.taken++;
50
- }
51
- else if (this.taken <= this.maximumToTake)
52
- {
53
- await this.innerIterator.next();
54
- this.taken++;
55
- }
56
- return this.hasCurrent();
57
- });
58
- }
59
-
60
- public hasStarted(): boolean
61
- {
62
- return this.started;
63
- }
64
-
65
- public getCurrent(): T
66
- {
67
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
68
-
69
- return this.innerIterator.getCurrent();
70
- }
71
-
72
- public start(): PromiseAsyncResult<this>
73
- {
74
- return AsyncIterator.start<T, this>(this);
75
- }
76
-
77
- public takeCurrent(): PromiseAsyncResult<T>
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<T[]>
93
- {
94
- return AsyncIterator.toArray(this);
95
- }
96
-
97
- public where(condition: (value: T) => boolean): AsyncIterator<T>
98
- {
99
- return AsyncIterator.where(this, condition);
100
- }
101
-
102
- public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): AsyncIterator<U>
103
- {
104
- return AsyncIterator.whereInstanceOf(this, typeCheck);
105
- }
106
-
107
- public whereInstanceOfType<U extends T>(type: Type<U>): AsyncIterator<U>
108
- {
109
- return AsyncIterator.whereInstanceOfType(this, type);
110
- }
111
-
112
- public map<TOutput>(mapping: (value: T) => (TOutput | PromiseLike<TOutput>)): AsyncIterator<TOutput>
113
- {
114
- return AsyncIterator.map(this, mapping);
115
- }
116
-
117
- public first(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
118
- {
119
- return AsyncIterator.first(this, condition);
120
- }
121
-
122
- public last(condition?: (value: T) => (boolean | PromiseLike<boolean>)): PromiseAsyncResult<T>
123
- {
124
- return AsyncIterator.last(this, condition);
125
- }
126
-
127
- public [Symbol.asyncIterator](): JavascriptAsyncIterator<T>
128
- {
129
- return AsyncIterator[Symbol.asyncIterator](this);
130
- }
131
-
132
- public take(maximumToTake: number): AsyncIterator<T>
133
- {
134
- return AsyncIterator.take(this, maximumToTake);
135
- }
136
-
137
- public skip(maximumToSkip: number): AsyncIterator<T>
138
- {
139
- return AsyncIterator.skip(this, maximumToSkip);
140
- }
141
- }
@@ -1,151 +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 iterates over a maximum number of values.
9
- */
10
- export class TakeIterator<T> implements Iterator<T>
11
- {
12
- private readonly innerIterator: Iterator<T>;
13
- private started: boolean;
14
- private readonly maximumToTake: number;
15
- private taken: number;
16
-
17
- private constructor(innerIterator: Iterator<T>, maximumToTake: number)
18
- {
19
- PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
20
-
21
- this.innerIterator = innerIterator;
22
- this.started = false;
23
- this.maximumToTake = maximumToTake;
24
- this.taken = 0;
25
- }
26
-
27
- public static create<T>(innerIterator: Iterator<T>, maximumToTake: number)
28
- {
29
- return new TakeIterator(innerIterator, maximumToTake);
30
- }
31
-
32
- public hasCurrent(): boolean
33
- {
34
- return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
35
- }
36
-
37
- public next(): SyncResult<boolean>
38
- {
39
- return SyncResult.create(() =>
40
- {
41
- if (this.maximumToTake <= 0)
42
- {
43
- return false;
44
- }
45
- else if (!this.hasStarted())
46
- {
47
- this.started = true;
48
- this.innerIterator.start().await();
49
- this.taken++;
50
- }
51
- else if (this.taken <= this.maximumToTake)
52
- {
53
- this.innerIterator.next().await();
54
- this.taken++;
55
- }
56
- return this.hasCurrent();
57
- });
58
- }
59
-
60
- public hasStarted(): boolean
61
- {
62
- return this.started;
63
- }
64
-
65
- public getCurrent(): T
66
- {
67
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
68
-
69
- return this.innerIterator.getCurrent();
70
- }
71
-
72
- public start(): SyncResult<this>
73
- {
74
- return Iterator.start<T, this>(this);
75
- }
76
-
77
- public takeCurrent(): SyncResult<T>
78
- {
79
- return Iterator.takeCurrent(this);
80
- }
81
-
82
- public any(): SyncResult<boolean>
83
- {
84
- return Iterator.any(this);
85
- }
86
-
87
- public getCount(): SyncResult<number>
88
- {
89
- return Iterator.getCount(this);
90
- }
91
-
92
- public toArray(): SyncResult<T[]>
93
- {
94
- return Iterator.toArray(this);
95
- }
96
-
97
- public concatenate(...toConcatenate: JavascriptIterable<T>[]): Iterator<T>
98
- {
99
- return Iterator.concatenate(this, ...toConcatenate);
100
- }
101
-
102
- public where(condition: (value: T) => boolean): Iterator<T>
103
- {
104
- return Iterator.where(this, condition);
105
- }
106
-
107
- public whereInstanceOf<U extends T>(typeCheck: (value: T) => value is U): Iterator<U>
108
- {
109
- return Iterator.whereInstanceOf(this, typeCheck);
110
- }
111
-
112
- public whereInstanceOfType<U extends T>(type: Type<U>): Iterator<U>
113
- {
114
- return Iterator.whereInstanceOfType(this, type);
115
- }
116
-
117
- public map<TOutput>(mapping: (value: T) => (TOutput | SyncResult<TOutput>)): Iterator<TOutput>
118
- {
119
- return Iterator.map(this, mapping);
120
- }
121
-
122
- public flatMap<TOutput>(mapping: (value: T) => JavascriptIterable<TOutput>): Iterator<TOutput>
123
- {
124
- return Iterator.flatMap(this, mapping);
125
- }
126
-
127
- public first(condition?: (value: T) => boolean): SyncResult<T>
128
- {
129
- return Iterator.first(this, condition);
130
- }
131
-
132
- public last(condition?: (value: T) => boolean): SyncResult<T>
133
- {
134
- return Iterator.last(this, condition);
135
- }
136
-
137
- public [Symbol.iterator](): JavascriptIterator<T>
138
- {
139
- return Iterator[Symbol.iterator](this);
140
- }
141
-
142
- public take(maximumToTake: number): Iterator<T>
143
- {
144
- return Iterator.take(this, maximumToTake);
145
- }
146
-
147
- public skip(maximumToSkip: number): Iterator<T>
148
- {
149
- return Iterator.skip(this, maximumToSkip);
150
- }
151
- }