@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,230 +1,230 @@
|
|
|
1
|
-
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
2
|
-
import { List } from "./list";
|
|
3
|
-
import { ListStack } from "./listStack";
|
|
4
|
-
import { PreCondition } from "./preCondition";
|
|
5
|
-
import { SearchControl } from "./searchControl";
|
|
6
|
-
import { Stack } from "./stack";
|
|
7
|
-
import { Set } from "./set";
|
|
8
|
-
import { Iterator } from "./iterator";
|
|
9
|
-
import { SyncResult } from "./syncResult";
|
|
10
|
-
import { isJavascriptIterable, Type } from "./types";
|
|
11
|
-
|
|
12
|
-
class SearchBreakError extends Error
|
|
13
|
-
{
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class DepthFirstSearch<TVisit,TResult> implements SearchControl<TVisit,TResult>, Iterator<TResult>
|
|
17
|
-
{
|
|
18
|
-
private readonly searchAction: (searchControl: SearchControl<TVisit,TResult>, visiting: TVisit) => void;
|
|
19
|
-
private readonly toVisit: ListStack<TVisit>;
|
|
20
|
-
private readonly visited: Set<TVisit>;
|
|
21
|
-
private readonly results: List<TResult>;
|
|
22
|
-
private started: boolean;
|
|
23
|
-
private done: boolean;
|
|
24
|
-
|
|
25
|
-
private constructor(initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, visiting: TVisit) => void)
|
|
26
|
-
{
|
|
27
|
-
PreCondition.assertNotEmpty(initialToVisit, "initialToVisit");
|
|
28
|
-
PreCondition.assertNotUndefinedAndNotNull(searchAction, "searchAction");
|
|
29
|
-
|
|
30
|
-
this.searchAction = searchAction;
|
|
31
|
-
this.toVisit = Stack.create();
|
|
32
|
-
this.toVisit.addAll(initialToVisit).await();
|
|
33
|
-
this.visited = Set.create();
|
|
34
|
-
this.results = List.create();
|
|
35
|
-
this.started = false;
|
|
36
|
-
this.done = false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public static create<TVisit,TResult>(initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, visiting: TVisit) => void): DepthFirstSearch<TVisit,TResult>
|
|
40
|
-
{
|
|
41
|
-
return new DepthFirstSearch(initialToVisit, searchAction);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public addToVisit(toVisit: TVisit): void
|
|
45
|
-
{
|
|
46
|
-
if (!this.hasVisited(toVisit))
|
|
47
|
-
{
|
|
48
|
-
this.toVisit.add(toVisit);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public addAllToVisit(values: JavascriptIterable<TVisit>): void
|
|
53
|
-
{
|
|
54
|
-
for (const value of values)
|
|
55
|
-
{
|
|
56
|
-
this.addToVisit(value);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public hasVisited(toVisit: TVisit): boolean
|
|
61
|
-
{
|
|
62
|
-
return this.visited.contains(toVisit).await();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public addResult(result: TResult): void
|
|
66
|
-
{
|
|
67
|
-
this.results.add(result);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public addResults(results: JavascriptIterable<TResult>): void
|
|
71
|
-
{
|
|
72
|
-
this.results.addAll(results);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public break(): never
|
|
76
|
-
{
|
|
77
|
-
throw new SearchBreakError();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public next(): SyncResult<boolean>
|
|
81
|
-
{
|
|
82
|
-
return SyncResult.create(() =>
|
|
83
|
-
{
|
|
84
|
-
let result: boolean = false;
|
|
85
|
-
if (!this.done)
|
|
86
|
-
{
|
|
87
|
-
if (!this.started)
|
|
88
|
-
{
|
|
89
|
-
this.started = true;
|
|
90
|
-
}
|
|
91
|
-
else
|
|
92
|
-
{
|
|
93
|
-
this.results.removeFirst().await();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
while (!this.hasCurrent() && this.toVisit.any().await())
|
|
97
|
-
{
|
|
98
|
-
const current: TVisit = this.toVisit.remove().await();
|
|
99
|
-
this.visited.add(current);
|
|
100
|
-
this.searchAction(this, current);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
result = this.hasCurrent();
|
|
104
|
-
this.done = !result;
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public hasStarted(): boolean
|
|
111
|
-
{
|
|
112
|
-
return this.started;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public hasCurrent(): boolean
|
|
116
|
-
{
|
|
117
|
-
return this.results.any().await();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public getCurrent(): TResult
|
|
121
|
-
{
|
|
122
|
-
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
123
|
-
|
|
124
|
-
return this.results.first().await();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public start(): SyncResult<this>
|
|
128
|
-
{
|
|
129
|
-
return Iterator.start<TResult,this>(this);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public takeCurrent(): SyncResult<TResult>
|
|
133
|
-
{
|
|
134
|
-
return Iterator.takeCurrent(this);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public any(): SyncResult<boolean>
|
|
138
|
-
{
|
|
139
|
-
return Iterator.any(this);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public getCount(): SyncResult<number>
|
|
143
|
-
{
|
|
144
|
-
return Iterator.getCount(this);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
public toArray(): SyncResult<TResult[]>
|
|
148
|
-
{
|
|
149
|
-
return Iterator.toArray(this);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public concatenate(...toConcatenate: JavascriptIterable<TResult>[]): Iterator<TResult>
|
|
153
|
-
{
|
|
154
|
-
return Iterator.concatenate(this, ...toConcatenate);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public where(condition: (value: TResult) => (boolean | SyncResult<boolean>)): Iterator<TResult>
|
|
158
|
-
{
|
|
159
|
-
return Iterator.where(this, condition);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public map<TOutput>(mapping: (value: TResult) => TOutput | SyncResult<TOutput>): Iterator<TOutput>
|
|
163
|
-
{
|
|
164
|
-
return Iterator.map(this, mapping);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public flatMap<TOutput>(mapping: (value: TResult) => JavascriptIterable<TOutput>): Iterator<TOutput>
|
|
168
|
-
{
|
|
169
|
-
return Iterator.flatMap(this, mapping);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public whereInstanceOf<U extends TResult>(typeCheck: (value: TResult) => value is U): Iterator<U>
|
|
173
|
-
{
|
|
174
|
-
return Iterator.whereInstanceOf(this, typeCheck);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public whereInstanceOfType<U extends TResult>(type: Type<U>): Iterator<U>
|
|
178
|
-
{
|
|
179
|
-
return Iterator.whereInstanceOfType(this, type);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public first(condition?: ((value: TResult) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TResult>
|
|
183
|
-
{
|
|
184
|
-
return Iterator.first(this, condition);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
public last(condition?: ((value: TResult) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TResult>
|
|
188
|
-
{
|
|
189
|
-
return Iterator.last(this, condition);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public take(maximumToTake: number): Iterator<TResult>
|
|
193
|
-
{
|
|
194
|
-
return Iterator.take(this, maximumToTake);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
public skip(maximumToSkip: number): Iterator<TResult>
|
|
198
|
-
{
|
|
199
|
-
return Iterator.skip(this, maximumToSkip);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
public [Symbol.iterator](): JavascriptIterator<TResult>
|
|
203
|
-
{
|
|
204
|
-
return Iterator[Symbol.iterator](this);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export function depthFirstSearch<TVisit,TResult>(initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void): Iterator<TResult>;
|
|
209
|
-
export function depthFirstSearch<TVisit,TResult>(parameters: { initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void }): Iterator<TResult>;
|
|
210
|
-
export function depthFirstSearch<TVisit,TResult>(parametersOrInitialToVisit: JavascriptIterable<TVisit> | { initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void }, searchAction?: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void): Iterator<TResult>
|
|
211
|
-
{
|
|
212
|
-
let initialToVisit: JavascriptIterable<TVisit>;
|
|
213
|
-
if (isJavascriptIterable(parametersOrInitialToVisit))
|
|
214
|
-
{
|
|
215
|
-
initialToVisit = parametersOrInitialToVisit;
|
|
216
|
-
searchAction = searchAction!;
|
|
217
|
-
}
|
|
218
|
-
else
|
|
219
|
-
{
|
|
220
|
-
PreCondition.assertNotUndefinedAndNotNull(parametersOrInitialToVisit, "parameters");
|
|
221
|
-
|
|
222
|
-
initialToVisit = parametersOrInitialToVisit.initialToVisit;
|
|
223
|
-
searchAction = parametersOrInitialToVisit.searchAction;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
PreCondition.assertNotUndefinedAndNotNull(initialToVisit, "initialToVisit");
|
|
227
|
-
PreCondition.assertNotUndefinedAndNotNull(searchAction, "searchAction");
|
|
228
|
-
|
|
229
|
-
return DepthFirstSearch.create(initialToVisit, searchAction);
|
|
1
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
2
|
+
import { List } from "./list";
|
|
3
|
+
import { ListStack } from "./listStack";
|
|
4
|
+
import { PreCondition } from "./preCondition";
|
|
5
|
+
import { SearchControl } from "./searchControl";
|
|
6
|
+
import { Stack } from "./stack";
|
|
7
|
+
import { Set } from "./set";
|
|
8
|
+
import { Iterator } from "./iterator";
|
|
9
|
+
import { SyncResult } from "./syncResult";
|
|
10
|
+
import { isJavascriptIterable, Type } from "./types";
|
|
11
|
+
|
|
12
|
+
class SearchBreakError extends Error
|
|
13
|
+
{
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class DepthFirstSearch<TVisit,TResult> implements SearchControl<TVisit,TResult>, Iterator<TResult>
|
|
17
|
+
{
|
|
18
|
+
private readonly searchAction: (searchControl: SearchControl<TVisit,TResult>, visiting: TVisit) => void;
|
|
19
|
+
private readonly toVisit: ListStack<TVisit>;
|
|
20
|
+
private readonly visited: Set<TVisit>;
|
|
21
|
+
private readonly results: List<TResult>;
|
|
22
|
+
private started: boolean;
|
|
23
|
+
private done: boolean;
|
|
24
|
+
|
|
25
|
+
private constructor(initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, visiting: TVisit) => void)
|
|
26
|
+
{
|
|
27
|
+
PreCondition.assertNotEmpty(initialToVisit, "initialToVisit");
|
|
28
|
+
PreCondition.assertNotUndefinedAndNotNull(searchAction, "searchAction");
|
|
29
|
+
|
|
30
|
+
this.searchAction = searchAction;
|
|
31
|
+
this.toVisit = Stack.create();
|
|
32
|
+
this.toVisit.addAll(initialToVisit).await();
|
|
33
|
+
this.visited = Set.create();
|
|
34
|
+
this.results = List.create();
|
|
35
|
+
this.started = false;
|
|
36
|
+
this.done = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static create<TVisit,TResult>(initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, visiting: TVisit) => void): DepthFirstSearch<TVisit,TResult>
|
|
40
|
+
{
|
|
41
|
+
return new DepthFirstSearch(initialToVisit, searchAction);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public addToVisit(toVisit: TVisit): void
|
|
45
|
+
{
|
|
46
|
+
if (!this.hasVisited(toVisit))
|
|
47
|
+
{
|
|
48
|
+
this.toVisit.add(toVisit);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public addAllToVisit(values: JavascriptIterable<TVisit>): void
|
|
53
|
+
{
|
|
54
|
+
for (const value of values)
|
|
55
|
+
{
|
|
56
|
+
this.addToVisit(value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public hasVisited(toVisit: TVisit): boolean
|
|
61
|
+
{
|
|
62
|
+
return this.visited.contains(toVisit).await();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public addResult(result: TResult): void
|
|
66
|
+
{
|
|
67
|
+
this.results.add(result);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public addResults(results: JavascriptIterable<TResult>): void
|
|
71
|
+
{
|
|
72
|
+
this.results.addAll(results);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public break(): never
|
|
76
|
+
{
|
|
77
|
+
throw new SearchBreakError();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public next(): SyncResult<boolean>
|
|
81
|
+
{
|
|
82
|
+
return SyncResult.create(() =>
|
|
83
|
+
{
|
|
84
|
+
let result: boolean = false;
|
|
85
|
+
if (!this.done)
|
|
86
|
+
{
|
|
87
|
+
if (!this.started)
|
|
88
|
+
{
|
|
89
|
+
this.started = true;
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
{
|
|
93
|
+
this.results.removeFirst().await();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
while (!this.hasCurrent() && this.toVisit.any().await())
|
|
97
|
+
{
|
|
98
|
+
const current: TVisit = this.toVisit.remove().await();
|
|
99
|
+
this.visited.add(current);
|
|
100
|
+
this.searchAction(this, current);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
result = this.hasCurrent();
|
|
104
|
+
this.done = !result;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public hasStarted(): boolean
|
|
111
|
+
{
|
|
112
|
+
return this.started;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public hasCurrent(): boolean
|
|
116
|
+
{
|
|
117
|
+
return this.results.any().await();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public getCurrent(): TResult
|
|
121
|
+
{
|
|
122
|
+
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
123
|
+
|
|
124
|
+
return this.results.first().await();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public start(): SyncResult<this>
|
|
128
|
+
{
|
|
129
|
+
return Iterator.start<TResult,this>(this);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public takeCurrent(): SyncResult<TResult>
|
|
133
|
+
{
|
|
134
|
+
return Iterator.takeCurrent(this);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public any(): SyncResult<boolean>
|
|
138
|
+
{
|
|
139
|
+
return Iterator.any(this);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public getCount(): SyncResult<number>
|
|
143
|
+
{
|
|
144
|
+
return Iterator.getCount(this);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public toArray(): SyncResult<TResult[]>
|
|
148
|
+
{
|
|
149
|
+
return Iterator.toArray(this);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public concatenate(...toConcatenate: JavascriptIterable<TResult>[]): Iterator<TResult>
|
|
153
|
+
{
|
|
154
|
+
return Iterator.concatenate(this, ...toConcatenate);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public where(condition: (value: TResult) => (boolean | SyncResult<boolean>)): Iterator<TResult>
|
|
158
|
+
{
|
|
159
|
+
return Iterator.where(this, condition);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public map<TOutput>(mapping: (value: TResult) => TOutput | SyncResult<TOutput>): Iterator<TOutput>
|
|
163
|
+
{
|
|
164
|
+
return Iterator.map(this, mapping);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public flatMap<TOutput>(mapping: (value: TResult) => JavascriptIterable<TOutput>): Iterator<TOutput>
|
|
168
|
+
{
|
|
169
|
+
return Iterator.flatMap(this, mapping);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public whereInstanceOf<U extends TResult>(typeCheck: (value: TResult) => value is U): Iterator<U>
|
|
173
|
+
{
|
|
174
|
+
return Iterator.whereInstanceOf(this, typeCheck);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public whereInstanceOfType<U extends TResult>(type: Type<U>): Iterator<U>
|
|
178
|
+
{
|
|
179
|
+
return Iterator.whereInstanceOfType(this, type);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public first(condition?: ((value: TResult) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TResult>
|
|
183
|
+
{
|
|
184
|
+
return Iterator.first(this, condition);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public last(condition?: ((value: TResult) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TResult>
|
|
188
|
+
{
|
|
189
|
+
return Iterator.last(this, condition);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public take(maximumToTake: number): Iterator<TResult>
|
|
193
|
+
{
|
|
194
|
+
return Iterator.take(this, maximumToTake);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public skip(maximumToSkip: number): Iterator<TResult>
|
|
198
|
+
{
|
|
199
|
+
return Iterator.skip(this, maximumToSkip);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public [Symbol.iterator](): JavascriptIterator<TResult>
|
|
203
|
+
{
|
|
204
|
+
return Iterator[Symbol.iterator](this);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function depthFirstSearch<TVisit,TResult>(initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void): Iterator<TResult>;
|
|
209
|
+
export function depthFirstSearch<TVisit,TResult>(parameters: { initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void }): Iterator<TResult>;
|
|
210
|
+
export function depthFirstSearch<TVisit,TResult>(parametersOrInitialToVisit: JavascriptIterable<TVisit> | { initialToVisit: JavascriptIterable<TVisit>, searchAction: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void }, searchAction?: (searchControl: SearchControl<TVisit,TResult>, current: TVisit) => void): Iterator<TResult>
|
|
211
|
+
{
|
|
212
|
+
let initialToVisit: JavascriptIterable<TVisit>;
|
|
213
|
+
if (isJavascriptIterable(parametersOrInitialToVisit))
|
|
214
|
+
{
|
|
215
|
+
initialToVisit = parametersOrInitialToVisit;
|
|
216
|
+
searchAction = searchAction!;
|
|
217
|
+
}
|
|
218
|
+
else
|
|
219
|
+
{
|
|
220
|
+
PreCondition.assertNotUndefinedAndNotNull(parametersOrInitialToVisit, "parameters");
|
|
221
|
+
|
|
222
|
+
initialToVisit = parametersOrInitialToVisit.initialToVisit;
|
|
223
|
+
searchAction = parametersOrInitialToVisit.searchAction;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
PreCondition.assertNotUndefinedAndNotNull(initialToVisit, "initialToVisit");
|
|
227
|
+
PreCondition.assertNotUndefinedAndNotNull(searchAction, "searchAction");
|
|
228
|
+
|
|
229
|
+
return DepthFirstSearch.create(initialToVisit, searchAction);
|
|
230
230
|
}
|
|
@@ -1,104 +1,104 @@
|
|
|
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 { ToStringFunctions } from "./toStringFunctions";
|
|
8
|
-
import { Type } from "./types";
|
|
9
|
-
|
|
10
|
-
export class FlatMapIterable<TInput,TOutput> implements Iterable<TOutput>
|
|
11
|
-
{
|
|
12
|
-
private readonly innerIterable: Iterable<TInput>;
|
|
13
|
-
private readonly mapping: (value: TInput) => JavascriptIterable<TOutput>;
|
|
14
|
-
|
|
15
|
-
private constructor(innerIterable: Iterable<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>)
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
PreCondition.assertNotUndefinedAndNotNull(innerIterable, "innerIterable");
|
|
19
|
-
PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
|
|
20
|
-
|
|
21
|
-
this.innerIterable = innerIterable;
|
|
22
|
-
this.mapping = mapping;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static create<TInput,TOutput>(innerIterable: Iterable<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>): FlatMapIterable<TInput,TOutput>
|
|
26
|
-
{
|
|
27
|
-
return new FlatMapIterable(innerIterable, mapping);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public iterate(): Iterator<TOutput>
|
|
31
|
-
{
|
|
32
|
-
return this.innerIterable.iterate().flatMap(this.mapping);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public toArray(): SyncResult<TOutput[]>
|
|
36
|
-
{
|
|
37
|
-
return Iterable.toArray<TOutput>(this);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public any(): SyncResult<boolean>
|
|
41
|
-
{
|
|
42
|
-
return Iterable.any(this);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public getCount(): SyncResult<number>
|
|
46
|
-
{
|
|
47
|
-
return Iterable.getCount(this);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public equals(right: JavascriptIterable<TOutput>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
51
|
-
{
|
|
52
|
-
return Iterable.equals(this, right, equalFunctions);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public toString(toStringFunctions?: ToStringFunctions): string
|
|
56
|
-
{
|
|
57
|
-
return Iterable.toString(this, toStringFunctions);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public concatenate(...toConcatenate: JavascriptIterable<TOutput>[]): Iterable<TOutput>
|
|
61
|
-
{
|
|
62
|
-
return Iterable.concatenate<TOutput>(this, ...toConcatenate);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public map<TOutput2>(mapping: (value: TOutput) => TOutput2 | SyncResult<TOutput2>): Iterable<TOutput2>
|
|
66
|
-
{
|
|
67
|
-
return Iterable.map(this, mapping);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public flatMap<TOutput2>(mapping: (value: TOutput) => JavascriptIterable<TOutput2>): Iterable<TOutput2>
|
|
71
|
-
{
|
|
72
|
-
return Iterable.flatMap(this, mapping);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public where(condition: (value: TOutput) => (boolean | SyncResult<boolean>)): Iterable<TOutput>
|
|
76
|
-
{
|
|
77
|
-
return Iterable.where(this, condition);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public instanceOf<TOutput2 extends TOutput>(typeOrTypeCheck: Type<TOutput2> | ((value: TOutput2) => value is TOutput2)): Iterable<TOutput2>
|
|
81
|
-
{
|
|
82
|
-
return Iterable.instanceOf<TOutput,TOutput2>(this, typeOrTypeCheck);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public first(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
|
|
86
|
-
{
|
|
87
|
-
return Iterable.first(this, condition);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public last(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
|
|
91
|
-
{
|
|
92
|
-
return Iterable.last(this, condition);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public contains(value: TOutput, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
96
|
-
{
|
|
97
|
-
return Iterable.contains(this, value, equalFunctions);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public [Symbol.iterator](): JavascriptIterator<TOutput>
|
|
101
|
-
{
|
|
102
|
-
return Iterable[Symbol.iterator](this);
|
|
103
|
-
}
|
|
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 { ToStringFunctions } from "./toStringFunctions";
|
|
8
|
+
import { Type } from "./types";
|
|
9
|
+
|
|
10
|
+
export class FlatMapIterable<TInput,TOutput> implements Iterable<TOutput>
|
|
11
|
+
{
|
|
12
|
+
private readonly innerIterable: Iterable<TInput>;
|
|
13
|
+
private readonly mapping: (value: TInput) => JavascriptIterable<TOutput>;
|
|
14
|
+
|
|
15
|
+
private constructor(innerIterable: Iterable<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>)
|
|
16
|
+
{
|
|
17
|
+
|
|
18
|
+
PreCondition.assertNotUndefinedAndNotNull(innerIterable, "innerIterable");
|
|
19
|
+
PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
|
|
20
|
+
|
|
21
|
+
this.innerIterable = innerIterable;
|
|
22
|
+
this.mapping = mapping;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static create<TInput,TOutput>(innerIterable: Iterable<TInput>, mapping: (value: TInput) => JavascriptIterable<TOutput>): FlatMapIterable<TInput,TOutput>
|
|
26
|
+
{
|
|
27
|
+
return new FlatMapIterable(innerIterable, mapping);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public iterate(): Iterator<TOutput>
|
|
31
|
+
{
|
|
32
|
+
return this.innerIterable.iterate().flatMap(this.mapping);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public toArray(): SyncResult<TOutput[]>
|
|
36
|
+
{
|
|
37
|
+
return Iterable.toArray<TOutput>(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public any(): SyncResult<boolean>
|
|
41
|
+
{
|
|
42
|
+
return Iterable.any(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public getCount(): SyncResult<number>
|
|
46
|
+
{
|
|
47
|
+
return Iterable.getCount(this);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public equals(right: JavascriptIterable<TOutput>, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
51
|
+
{
|
|
52
|
+
return Iterable.equals(this, right, equalFunctions);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public toString(toStringFunctions?: ToStringFunctions): string
|
|
56
|
+
{
|
|
57
|
+
return Iterable.toString(this, toStringFunctions);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public concatenate(...toConcatenate: JavascriptIterable<TOutput>[]): Iterable<TOutput>
|
|
61
|
+
{
|
|
62
|
+
return Iterable.concatenate<TOutput>(this, ...toConcatenate);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public map<TOutput2>(mapping: (value: TOutput) => TOutput2 | SyncResult<TOutput2>): Iterable<TOutput2>
|
|
66
|
+
{
|
|
67
|
+
return Iterable.map(this, mapping);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public flatMap<TOutput2>(mapping: (value: TOutput) => JavascriptIterable<TOutput2>): Iterable<TOutput2>
|
|
71
|
+
{
|
|
72
|
+
return Iterable.flatMap(this, mapping);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public where(condition: (value: TOutput) => (boolean | SyncResult<boolean>)): Iterable<TOutput>
|
|
76
|
+
{
|
|
77
|
+
return Iterable.where(this, condition);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public instanceOf<TOutput2 extends TOutput>(typeOrTypeCheck: Type<TOutput2> | ((value: TOutput2) => value is TOutput2)): Iterable<TOutput2>
|
|
81
|
+
{
|
|
82
|
+
return Iterable.instanceOf<TOutput,TOutput2>(this, typeOrTypeCheck);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public first(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
|
|
86
|
+
{
|
|
87
|
+
return Iterable.first(this, condition);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public last(condition?: ((value: TOutput) => (boolean | SyncResult<boolean>)) | undefined): SyncResult<TOutput>
|
|
91
|
+
{
|
|
92
|
+
return Iterable.last(this, condition);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public contains(value: TOutput, equalFunctions?: EqualFunctions): SyncResult<boolean>
|
|
96
|
+
{
|
|
97
|
+
return Iterable.contains(this, value, equalFunctions);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public [Symbol.iterator](): JavascriptIterator<TOutput>
|
|
101
|
+
{
|
|
102
|
+
return Iterable[Symbol.iterator](this);
|
|
103
|
+
}
|
|
104
104
|
}
|