@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.
- package/.github/workflows/publish.yml +54 -38
- package/package.json +9 -2
- package/sources/asyncIterator.ts +436 -436
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
- package/sources/asyncResult.ts +95 -95
- package/sources/byteList.ts +201 -201
- package/sources/byteListStream.ts +120 -120
- package/sources/byteReadStream.ts +23 -23
- package/sources/byteWriteStream.ts +15 -15
- package/sources/characterList.ts +194 -194
- package/sources/characterListStream.ts +150 -150
- package/sources/characterReadStream.ts +80 -80
- package/sources/characterReadStreamIterator.ts +127 -127
- package/sources/concatenateIterable.ts +118 -118
- package/sources/concatenateIterator.ts +164 -164
- package/sources/currentProcess.ts +157 -157
- package/sources/dateTime.ts +129 -129
- package/sources/depthFirstSearch.ts +229 -229
- package/sources/flatMapIterable.ts +103 -103
- package/sources/flatMapIterator.ts +151 -151
- package/sources/generator.ts +250 -250
- package/sources/index.ts +1 -1
- package/sources/iterator.ts +480 -480
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
- package/sources/javascriptSetSet.ts +133 -133
- package/sources/listQueue.ts +61 -61
- package/sources/listStack.ts +61 -61
- package/sources/luxonDateTime.ts +108 -108
- package/sources/mapAsyncIterator.ts +140 -140
- package/sources/mutableMap.ts +291 -291
- package/sources/node.ts +36 -36
- package/sources/promiseAsyncResult.ts +173 -173
- package/sources/queue.ts +48 -48
- package/sources/recreationDotGovClient.ts +258 -258
- package/sources/searchControl.ts +41 -41
- package/sources/set.ts +243 -243
- package/sources/skipAsyncIterator.ts +144 -144
- package/sources/stack.ts +47 -47
- package/sources/syncResult.ts +299 -299
- package/sources/takeAsyncIterator.ts +140 -140
- package/sources/whereAsyncIterator.ts +142 -142
- package/sources/wonderlandTrailClient.ts +1502 -1502
- package/tests/assertTestTests.ts +74 -74
- package/tests/byteListStreamTests.ts +389 -389
- package/tests/byteListTests.ts +26 -26
- package/tests/characterListStreamTests.ts +390 -390
- package/tests/characterListTests.ts +249 -249
- package/tests/dateTimeTests.ts +29 -29
- package/tests/depthFirstSearchTests.ts +105 -105
- package/tests/generatorTests.ts +85 -85
- package/tests/mutableMapTests.ts +153 -153
- package/tests/promiseAsyncResultTests.ts +687 -687
- package/tests/queueTests.ts +28 -28
- package/tests/recreationDotGovClientTests.ts +190 -190
- package/tests/setTests.ts +139 -139
- package/tests/stackTests.ts +65 -65
- package/tests/syncResultTests.ts +1250 -1250
- package/tests/wonderlandTrailClientTests.ts +451 -451
- package/tsconfig.json +3 -0
- 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
|
}
|