@everyonesoftware/common 1.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 (60) hide show
  1. package/.github/workflows/publish.yml +54 -38
  2. package/package.json +9 -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/tsconfig.json +3 -0
  60. package/tsup.config.ts +12 -12
@@ -1,152 +1,152 @@
1
- import { JavascriptIterable, JavascriptIterator } from "./javascript";
2
- import { PreCondition } from "./preCondition";
3
- import { Iterator } from "./iterator";
4
- import { SyncResult } from "./syncResult";
5
- import { Type } from "./types";
6
-
7
- export class FlatMapIterator<TInput,TOutput> implements Iterator<TOutput>
8
- {
9
- private readonly innerIterator: Iterator<TInput>;
10
- private readonly mapping: (value: TInput) => JavascriptIterable<TOutput>;
11
- private mappingIterator: Iterator<TOutput> | undefined;
12
- private started: boolean;
13
-
14
- private constructor(innerIterator: Iterator<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>)
15
- {
16
- PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
17
- PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
18
-
19
- this.innerIterator = innerIterator;
20
- this.mapping = mapping;
21
- this.started = false;
22
- }
23
-
24
- public static create<TInput,TOutput>(innerIterator: Iterator<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>): FlatMapIterator<TInput,TOutput>
25
- {
26
- return new FlatMapIterator(innerIterator, mapping);
27
- }
28
-
29
- public next(): SyncResult<boolean>
30
- {
31
- return SyncResult.create(() =>
32
- {
33
- this.innerIterator.start().await();
34
-
35
- while (this.innerIterator.hasCurrent())
36
- {
37
- if (this.mappingIterator === undefined)
38
- {
39
- this.mappingIterator = Iterator.create(this.mapping(this.innerIterator.getCurrent()));
40
- }
41
-
42
- if (this.mappingIterator.next().await())
43
- {
44
- break;
45
- }
46
- else if (this.innerIterator.next().await())
47
- {
48
- this.mappingIterator = undefined;
49
- }
50
- }
51
-
52
- return this.hasCurrent();
53
- });
54
- }
55
-
56
- public hasStarted(): boolean
57
- {
58
- return this.started;
59
- }
60
-
61
- public hasCurrent(): boolean
62
- {
63
- return this.mappingIterator?.hasCurrent() ?? false;
64
- }
65
-
66
- public getCurrent(): TOutput
67
- {
68
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
69
-
70
- return this.mappingIterator!.getCurrent();
71
- }
72
-
73
- public start(): SyncResult<this>
74
- {
75
- return Iterator.start<TOutput,this>(this);
76
- }
77
-
78
- public takeCurrent(): SyncResult<TOutput>
79
- {
80
- return Iterator.takeCurrent(this);
81
- }
82
-
83
- public any(): SyncResult<boolean>
84
- {
85
- return Iterator.any(this);
86
- }
87
-
88
- public getCount(): SyncResult<number>
89
- {
90
- return Iterator.getCount(this);
91
- }
92
-
93
- public toArray(): SyncResult<TOutput[]>
94
- {
95
- return Iterator.toArray(this);
96
- }
97
-
98
- public concatenate(...toConcatenate: JavascriptIterable<TOutput>[]): Iterator<TOutput>
99
- {
100
- return Iterator.concatenate(this, ...toConcatenate);
101
- }
102
-
103
- public where(condition: (value: TOutput) => (boolean | SyncResult<boolean>)): Iterator<TOutput>
104
- {
105
- return Iterator.where(this, condition);
106
- }
107
-
108
- public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | SyncResult<TOutput2>)): Iterator<TOutput2>
109
- {
110
- return Iterator.map(this, mapping);
111
- }
112
-
113
- public flatMap<TOutput2>(mapping: (value: TOutput) => JavascriptIterable<TOutput2>): Iterator<TOutput2>
114
- {
115
- return Iterator.flatMap(this, mapping);
116
- }
117
-
118
- public whereInstanceOf<U extends TOutput>(typeCheck: (value: TOutput) => value is U): Iterator<U>
119
- {
120
- return Iterator.whereInstanceOf(this, typeCheck);
121
- }
122
-
123
- public whereInstanceOfType<U extends TOutput>(type: Type<U>): Iterator<U>
124
- {
125
- return Iterator.whereInstanceOfType(this, type);
126
- }
127
-
128
- public first(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
129
- {
130
- return Iterator.first(this, condition);
131
- }
132
-
133
- public last(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
134
- {
135
- return Iterator.last(this, condition);
136
- }
137
-
138
- public take(maximumToTake: number): Iterator<TOutput>
139
- {
140
- return Iterator.take(this, maximumToTake);
141
- }
142
-
143
- public skip(maximumToSkip: number): Iterator<TOutput>
144
- {
145
- return Iterator.skip(this, maximumToSkip);
146
- }
147
-
148
- public [Symbol.iterator](): JavascriptIterator<TOutput>
149
- {
150
- return Iterator[Symbol.iterator](this);
151
- }
1
+ import { JavascriptIterable, JavascriptIterator } from "./javascript";
2
+ import { PreCondition } from "./preCondition";
3
+ import { Iterator } from "./iterator";
4
+ import { SyncResult } from "./syncResult";
5
+ import { Type } from "./types";
6
+
7
+ export class FlatMapIterator<TInput,TOutput> implements Iterator<TOutput>
8
+ {
9
+ private readonly innerIterator: Iterator<TInput>;
10
+ private readonly mapping: (value: TInput) => JavascriptIterable<TOutput>;
11
+ private mappingIterator: Iterator<TOutput> | undefined;
12
+ private started: boolean;
13
+
14
+ private constructor(innerIterator: Iterator<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>)
15
+ {
16
+ PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
17
+ PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
18
+
19
+ this.innerIterator = innerIterator;
20
+ this.mapping = mapping;
21
+ this.started = false;
22
+ }
23
+
24
+ public static create<TInput,TOutput>(innerIterator: Iterator<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>): FlatMapIterator<TInput,TOutput>
25
+ {
26
+ return new FlatMapIterator(innerIterator, mapping);
27
+ }
28
+
29
+ public next(): SyncResult<boolean>
30
+ {
31
+ return SyncResult.create(() =>
32
+ {
33
+ this.innerIterator.start().await();
34
+
35
+ while (this.innerIterator.hasCurrent())
36
+ {
37
+ if (this.mappingIterator === undefined)
38
+ {
39
+ this.mappingIterator = Iterator.create(this.mapping(this.innerIterator.getCurrent()));
40
+ }
41
+
42
+ if (this.mappingIterator.next().await())
43
+ {
44
+ break;
45
+ }
46
+ else if (this.innerIterator.next().await())
47
+ {
48
+ this.mappingIterator = undefined;
49
+ }
50
+ }
51
+
52
+ return this.hasCurrent();
53
+ });
54
+ }
55
+
56
+ public hasStarted(): boolean
57
+ {
58
+ return this.started;
59
+ }
60
+
61
+ public hasCurrent(): boolean
62
+ {
63
+ return this.mappingIterator?.hasCurrent() ?? false;
64
+ }
65
+
66
+ public getCurrent(): TOutput
67
+ {
68
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
69
+
70
+ return this.mappingIterator!.getCurrent();
71
+ }
72
+
73
+ public start(): SyncResult<this>
74
+ {
75
+ return Iterator.start<TOutput,this>(this);
76
+ }
77
+
78
+ public takeCurrent(): SyncResult<TOutput>
79
+ {
80
+ return Iterator.takeCurrent(this);
81
+ }
82
+
83
+ public any(): SyncResult<boolean>
84
+ {
85
+ return Iterator.any(this);
86
+ }
87
+
88
+ public getCount(): SyncResult<number>
89
+ {
90
+ return Iterator.getCount(this);
91
+ }
92
+
93
+ public toArray(): SyncResult<TOutput[]>
94
+ {
95
+ return Iterator.toArray(this);
96
+ }
97
+
98
+ public concatenate(...toConcatenate: JavascriptIterable<TOutput>[]): Iterator<TOutput>
99
+ {
100
+ return Iterator.concatenate(this, ...toConcatenate);
101
+ }
102
+
103
+ public where(condition: (value: TOutput) => (boolean | SyncResult<boolean>)): Iterator<TOutput>
104
+ {
105
+ return Iterator.where(this, condition);
106
+ }
107
+
108
+ public map<TOutput2>(mapping: (value: TOutput) => (TOutput2 | SyncResult<TOutput2>)): Iterator<TOutput2>
109
+ {
110
+ return Iterator.map(this, mapping);
111
+ }
112
+
113
+ public flatMap<TOutput2>(mapping: (value: TOutput) => JavascriptIterable<TOutput2>): Iterator<TOutput2>
114
+ {
115
+ return Iterator.flatMap(this, mapping);
116
+ }
117
+
118
+ public whereInstanceOf<U extends TOutput>(typeCheck: (value: TOutput) => value is U): Iterator<U>
119
+ {
120
+ return Iterator.whereInstanceOf(this, typeCheck);
121
+ }
122
+
123
+ public whereInstanceOfType<U extends TOutput>(type: Type<U>): Iterator<U>
124
+ {
125
+ return Iterator.whereInstanceOfType(this, type);
126
+ }
127
+
128
+ public first(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
129
+ {
130
+ return Iterator.first(this, condition);
131
+ }
132
+
133
+ public last(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
134
+ {
135
+ return Iterator.last(this, condition);
136
+ }
137
+
138
+ public take(maximumToTake: number): Iterator<TOutput>
139
+ {
140
+ return Iterator.take(this, maximumToTake);
141
+ }
142
+
143
+ public skip(maximumToSkip: number): Iterator<TOutput>
144
+ {
145
+ return Iterator.skip(this, maximumToSkip);
146
+ }
147
+
148
+ public [Symbol.iterator](): JavascriptIterator<TOutput>
149
+ {
150
+ return Iterator[Symbol.iterator](this);
151
+ }
152
152
  }