semantic-typescript 0.3.3 → 0.3.8
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/dist/collectable.d.ts +19 -24
- package/dist/collectable.js +373 -175
- package/dist/collector.d.ts +101 -24
- package/dist/collector.js +402 -146
- package/dist/factory.d.ts +38 -8
- package/dist/factory.js +300 -163
- package/dist/guard.d.ts +8 -3
- package/dist/guard.js +29 -5
- package/dist/hook.d.ts +13 -0
- package/dist/hook.js +114 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/optional.js +36 -3
- package/dist/semantic.d.ts +17 -10
- package/dist/semantic.js +355 -195
- package/dist/statistics.d.ts +13 -17
- package/dist/statistics.js +234 -522
- package/dist/utility.d.ts +4 -0
- package/dist/utility.js +2 -1
- package/dist/window.d.ts +12 -0
- package/dist/window.js +70 -0
- package/package.json +1 -1
- package/readme.cn.md +732 -210
- package/readme.md +426 -150
package/dist/collectable.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindFirst, useFindLast, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, useReduce, useToArray, useToMap, useToSet, useWrite } from "./collector";
|
|
2
|
-
import {
|
|
3
|
-
import { isBigInt, isCollector, isFunction, isIterable, isObject, isString } from "./guard";
|
|
1
|
+
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray, useToAsyncGeneratorFunction, useToGeneratorFunction, useToMap, useToSet, useWrite } from "./collector";
|
|
2
|
+
import { isBigInt, isCollector, isFunction, isObject, isString } from "./guard";
|
|
4
3
|
import { useCompare } from "./hook";
|
|
5
4
|
import { Optional } from "./optional";
|
|
6
5
|
import { Semantic } from "./semantic";
|
|
7
|
-
import { CollectableSymbol, OrderedCollectableSymbol, UnorderedCollectableSymbol
|
|
6
|
+
import { CollectableSymbol, OrderedCollectableSymbol, UnorderedCollectableSymbol } from "./symbol";
|
|
8
7
|
import { invalidate, validate } from "./utility";
|
|
9
8
|
export class Collectable {
|
|
10
9
|
Collectable = CollectableSymbol;
|
|
11
10
|
constructor() {
|
|
11
|
+
Object.defineProperty(this, "Collectable", {
|
|
12
|
+
value: CollectableSymbol,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
writable: false,
|
|
15
|
+
configurable: false
|
|
16
|
+
});
|
|
17
|
+
Object.freeze(this);
|
|
12
18
|
}
|
|
13
19
|
anyMatch(predicate) {
|
|
14
20
|
if (isFunction(predicate)) {
|
|
15
|
-
|
|
21
|
+
try {
|
|
22
|
+
return useAnyMatch(predicate).collect(this);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error("Uncaught error on anyMatch.");
|
|
26
|
+
}
|
|
16
27
|
}
|
|
17
28
|
throw new TypeError("Predicate must be a function.");
|
|
18
29
|
}
|
|
@@ -20,43 +31,63 @@ export class Collectable {
|
|
|
20
31
|
return useAllMatch(predicate).collect(this);
|
|
21
32
|
}
|
|
22
33
|
collect(argument1, argument2, argument3, argument4) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
try {
|
|
35
|
+
if (isCollector(argument1)) {
|
|
36
|
+
let collector = argument1;
|
|
37
|
+
return collector.collect(this);
|
|
38
|
+
}
|
|
39
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
40
|
+
let identity = argument1;
|
|
41
|
+
let accumulator = argument2;
|
|
42
|
+
let finisher = argument3;
|
|
43
|
+
return useCollect(identity, accumulator, finisher).collect(this);
|
|
44
|
+
}
|
|
45
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
46
|
+
let identity = argument1;
|
|
47
|
+
let interrupt = argument2;
|
|
48
|
+
let accumulator = argument3;
|
|
49
|
+
let finisher = argument4;
|
|
50
|
+
return useCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new Error("Uncaught error on collect.");
|
|
39
55
|
}
|
|
40
56
|
throw new TypeError("Invalid arguments.");
|
|
41
57
|
}
|
|
42
58
|
count() {
|
|
43
|
-
return useCount().collect(this);
|
|
59
|
+
return useCount().collect(this.source());
|
|
44
60
|
}
|
|
45
61
|
error(argument1, argument2, argument3) {
|
|
46
62
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
47
|
-
|
|
63
|
+
try {
|
|
64
|
+
useError().collect(this.source());
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw new Error("Uncaught error on error.");
|
|
68
|
+
}
|
|
48
69
|
}
|
|
49
70
|
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
try {
|
|
72
|
+
let accumulator = argument1;
|
|
73
|
+
useError(accumulator).collect(this.source());
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error("Uncaught error on error.");
|
|
77
|
+
}
|
|
52
78
|
}
|
|
53
79
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
try {
|
|
81
|
+
let prefix = argument1;
|
|
82
|
+
let accumulator = argument2;
|
|
83
|
+
let suffix = argument3;
|
|
84
|
+
useError(prefix, accumulator, suffix).collect(this.source());
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw new Error("Uncaught error on error.");
|
|
88
|
+
}
|
|
58
89
|
}
|
|
59
|
-
{
|
|
90
|
+
else {
|
|
60
91
|
throw new TypeError("Invalid arguments.");
|
|
61
92
|
}
|
|
62
93
|
}
|
|
@@ -64,17 +95,55 @@ export class Collectable {
|
|
|
64
95
|
return this.count() === 0n;
|
|
65
96
|
}
|
|
66
97
|
findAny() {
|
|
67
|
-
|
|
98
|
+
try {
|
|
99
|
+
return useFindAny().collect(this.source());
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw new Error("Uncaught error on findAny.");
|
|
103
|
+
}
|
|
68
104
|
}
|
|
69
105
|
findFirst() {
|
|
70
|
-
|
|
106
|
+
try {
|
|
107
|
+
return useFindFirst().collect(this.source());
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new Error("Uncaught error on findFirst.");
|
|
111
|
+
}
|
|
71
112
|
}
|
|
72
113
|
findLast() {
|
|
73
|
-
|
|
114
|
+
try {
|
|
115
|
+
return useFindLast().collect(this.source());
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw new Error("Uncaught error on findLast.");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
findMaximum(argument1) {
|
|
122
|
+
try {
|
|
123
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
124
|
+
return useFindMaximum(comparator).collect(this.source());
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw new Error("Uncaught error on findMaximum.");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
findMinimum(argument1) {
|
|
131
|
+
try {
|
|
132
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
133
|
+
return useFindMinimum(comparator).collect(this.source());
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new Error("Uncaught error on findMinimum.");
|
|
137
|
+
}
|
|
74
138
|
}
|
|
75
139
|
forEach(action) {
|
|
76
140
|
if (isFunction(action)) {
|
|
77
|
-
|
|
141
|
+
try {
|
|
142
|
+
useForEach(action).collect(this);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
throw new Error("Uncaught error on forEach.");
|
|
146
|
+
}
|
|
78
147
|
}
|
|
79
148
|
else {
|
|
80
149
|
throw new TypeError("Action must be a function.");
|
|
@@ -82,97 +151,162 @@ export class Collectable {
|
|
|
82
151
|
}
|
|
83
152
|
group(classifier) {
|
|
84
153
|
if (isFunction(classifier)) {
|
|
85
|
-
|
|
154
|
+
try {
|
|
155
|
+
return useGroup(classifier).collect(this.source());
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
throw new Error("Uncaught error on group.");
|
|
159
|
+
}
|
|
86
160
|
}
|
|
87
161
|
throw new TypeError("Classifier must be a function.");
|
|
88
162
|
}
|
|
89
163
|
groupBy(keyExtractor, valueExtractor) {
|
|
90
164
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
91
|
-
|
|
165
|
+
try {
|
|
166
|
+
return useGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new Error("Uncaught error on groupBy.");
|
|
170
|
+
}
|
|
92
171
|
}
|
|
93
172
|
throw new TypeError("Key and value extractors must be functions.");
|
|
94
173
|
}
|
|
95
174
|
join(argument1, argument2, argument3) {
|
|
96
175
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
97
|
-
|
|
176
|
+
try {
|
|
177
|
+
return useJoin().collect(this.source());
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
throw new Error("Uncaught error on join.");
|
|
181
|
+
}
|
|
98
182
|
}
|
|
99
|
-
if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
100
|
-
|
|
101
|
-
|
|
183
|
+
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
184
|
+
try {
|
|
185
|
+
let delimiter = argument1;
|
|
186
|
+
return useJoin(delimiter).collect(this.source());
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
throw new Error("Uncaught error on join.");
|
|
190
|
+
}
|
|
102
191
|
}
|
|
103
|
-
if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
192
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
193
|
+
try {
|
|
194
|
+
let prefix = argument1;
|
|
195
|
+
let accumulator = argument2;
|
|
196
|
+
let suffix = argument3;
|
|
197
|
+
return useJoin(prefix, accumulator, suffix).collect(this.source());
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
throw new Error("Uncaught error on join.");
|
|
201
|
+
}
|
|
108
202
|
}
|
|
109
|
-
if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
203
|
+
else if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
204
|
+
try {
|
|
205
|
+
let prefix = argument1;
|
|
206
|
+
let delimiter = argument2;
|
|
207
|
+
let suffix = argument3;
|
|
208
|
+
return useJoin(prefix, delimiter, suffix).collect(this.source());
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
throw new Error("Uncaught error on join.");
|
|
212
|
+
}
|
|
114
213
|
}
|
|
115
214
|
throw new TypeError("Invalid arguments.");
|
|
116
215
|
}
|
|
117
216
|
log(argument1, argument2, argument3) {
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
217
|
+
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
218
|
+
try {
|
|
219
|
+
let accumulator = argument1;
|
|
220
|
+
useLog(accumulator).collect(this.source());
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
throw new Error("Uncaught error on log.");
|
|
224
|
+
}
|
|
124
225
|
}
|
|
125
226
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
227
|
+
try {
|
|
228
|
+
let prefix = argument1;
|
|
229
|
+
let accumulator = argument2;
|
|
230
|
+
let suffix = argument3;
|
|
231
|
+
useLog(prefix, accumulator, suffix).collect(this.source());
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
throw new Error("Uncaught error on log.");
|
|
235
|
+
}
|
|
130
236
|
}
|
|
131
|
-
{
|
|
132
|
-
|
|
237
|
+
else {
|
|
238
|
+
try {
|
|
239
|
+
useLog().collect(this.source());
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
throw new Error("Uncaught error on log.");
|
|
243
|
+
}
|
|
133
244
|
}
|
|
134
245
|
}
|
|
135
246
|
nonMatch(predicate) {
|
|
136
247
|
if (isFunction(predicate)) {
|
|
137
|
-
|
|
248
|
+
try {
|
|
249
|
+
return useNoneMatch(predicate).collect(this.source());
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
throw new Error("Uncaught error on nonMatch.");
|
|
253
|
+
}
|
|
138
254
|
}
|
|
139
255
|
throw new TypeError("Predicate must be a function.");
|
|
140
256
|
}
|
|
141
257
|
partition(count) {
|
|
142
258
|
if (isBigInt(count)) {
|
|
143
|
-
|
|
259
|
+
try {
|
|
260
|
+
return usePartition(count).collect(this.source());
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
throw new Error("Uncaught error on partition.");
|
|
264
|
+
}
|
|
144
265
|
}
|
|
145
266
|
throw new TypeError("Count must be a BigInt.");
|
|
146
267
|
}
|
|
147
268
|
partitionBy(classifier) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return result;
|
|
159
|
-
});
|
|
269
|
+
if (isFunction(classifier)) {
|
|
270
|
+
try {
|
|
271
|
+
let collector = usePartitionBy(classifier);
|
|
272
|
+
return collector.collect(this.source());
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
throw new Error("Uncaught error on partitionBy.");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
throw new TypeError("Classifier must be a function.");
|
|
160
279
|
}
|
|
161
280
|
reduce(argument1, argument2, argument3) {
|
|
162
281
|
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
163
|
-
|
|
164
|
-
|
|
282
|
+
try {
|
|
283
|
+
let accumulator = argument1;
|
|
284
|
+
return useReduce(accumulator).collect(this.source());
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
throw new Error("Uncaught error on reduce.");
|
|
288
|
+
}
|
|
165
289
|
}
|
|
166
290
|
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
291
|
+
try {
|
|
292
|
+
let identity = argument1;
|
|
293
|
+
let accumulator = argument2;
|
|
294
|
+
return useReduce(identity, accumulator).collect(this.source());
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
throw new Error("Uncaught error on reduce.");
|
|
298
|
+
}
|
|
170
299
|
}
|
|
171
300
|
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
301
|
+
try {
|
|
302
|
+
let identity = argument1;
|
|
303
|
+
let accumulator = argument2;
|
|
304
|
+
let finisher = argument3;
|
|
305
|
+
return useReduce(identity, accumulator, finisher).collect(this.source());
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
throw new Error("Uncaught error on reduce.");
|
|
309
|
+
}
|
|
176
310
|
}
|
|
177
311
|
else {
|
|
178
312
|
throw new TypeError("Invalid arguments.");
|
|
@@ -180,143 +314,207 @@ export class Collectable {
|
|
|
180
314
|
}
|
|
181
315
|
semantic() {
|
|
182
316
|
let source = this.source();
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
317
|
+
if (isFunction(source)) {
|
|
318
|
+
try {
|
|
319
|
+
return new Semantic(source);
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
throw new Error("Uncaught error on semantic.");
|
|
323
|
+
}
|
|
188
324
|
}
|
|
189
325
|
else {
|
|
190
326
|
throw new TypeError("Invalid source.");
|
|
191
327
|
}
|
|
192
328
|
}
|
|
193
329
|
toArray() {
|
|
194
|
-
|
|
330
|
+
try {
|
|
331
|
+
return useToArray().collect(this.source());
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
throw new Error("Uncaught error on toArray.");
|
|
335
|
+
}
|
|
195
336
|
}
|
|
196
337
|
toMap(keyExtractor, valueExtractor) {
|
|
197
|
-
|
|
338
|
+
try {
|
|
339
|
+
return useToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
throw new Error("Uncaught error on toMap.");
|
|
343
|
+
}
|
|
198
344
|
}
|
|
199
345
|
toSet() {
|
|
200
|
-
|
|
346
|
+
try {
|
|
347
|
+
return useToSet().collect(this.source());
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
throw new Error("Uncaught error on toSet.");
|
|
351
|
+
}
|
|
201
352
|
}
|
|
202
353
|
write(argument1, argument2) {
|
|
203
354
|
if (isObject(argument1)) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
355
|
+
try {
|
|
356
|
+
let stream = argument1;
|
|
357
|
+
if (isFunction(argument2)) {
|
|
358
|
+
let accumulator = argument2;
|
|
359
|
+
return useWrite(stream, accumulator).collect(this.source());
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
return useWrite(stream).collect(this.source());
|
|
363
|
+
}
|
|
208
364
|
}
|
|
209
|
-
|
|
210
|
-
|
|
365
|
+
catch (error) {
|
|
366
|
+
throw new Error("Uncaught error on write.");
|
|
211
367
|
}
|
|
212
368
|
}
|
|
213
369
|
throw new TypeError("Invalid arguments.");
|
|
214
370
|
}
|
|
215
371
|
}
|
|
216
372
|
;
|
|
373
|
+
Object.freeze(Collectable);
|
|
374
|
+
Object.freeze(Collectable.prototype);
|
|
375
|
+
Object.freeze(Object.getPrototypeOf(Collectable.prototype));
|
|
217
376
|
export class UnorderedCollectable extends Collectable {
|
|
218
377
|
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
219
378
|
generator;
|
|
220
|
-
constructor(
|
|
379
|
+
constructor(argument1) {
|
|
221
380
|
super();
|
|
222
|
-
|
|
381
|
+
if (isFunction(argument1)) {
|
|
382
|
+
this.generator = argument1;
|
|
383
|
+
Object.defineProperties(this, {
|
|
384
|
+
"UnorderedCollectable": {
|
|
385
|
+
value: UnorderedCollectableSymbol,
|
|
386
|
+
writable: false,
|
|
387
|
+
enumerable: false,
|
|
388
|
+
configurable: false
|
|
389
|
+
},
|
|
390
|
+
"generator": {
|
|
391
|
+
value: this.generator,
|
|
392
|
+
writable: false,
|
|
393
|
+
enumerable: false,
|
|
394
|
+
configurable: false
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
Object.freeze(this);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
401
|
+
}
|
|
223
402
|
}
|
|
224
403
|
source() {
|
|
225
404
|
return this.generator;
|
|
226
405
|
}
|
|
406
|
+
*[Symbol.iterator]() {
|
|
407
|
+
try {
|
|
408
|
+
let collector = useToGeneratorFunction();
|
|
409
|
+
yield* collector.collect(this.generator);
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
throw new Error("Uncaught error on Generator.");
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async *[Symbol.asyncIterator]() {
|
|
416
|
+
try {
|
|
417
|
+
let collector = useToAsyncGeneratorFunction();
|
|
418
|
+
yield* collector.collect(this.generator);
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
227
424
|
}
|
|
228
425
|
;
|
|
426
|
+
Object.freeze(UnorderedCollectable);
|
|
427
|
+
Object.freeze(UnorderedCollectable.prototype);
|
|
428
|
+
Object.freeze(Object.getPrototypeOf(UnorderedCollectable.prototype));
|
|
229
429
|
export class OrderedCollectable extends Collectable {
|
|
230
430
|
OrderedCollectable = OrderedCollectableSymbol;
|
|
231
|
-
|
|
431
|
+
buffer;
|
|
232
432
|
constructor(argument1, argument2) {
|
|
233
433
|
super();
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
434
|
+
if (isFunction(argument1)) {
|
|
435
|
+
try {
|
|
436
|
+
if (isFunction(argument2)) {
|
|
437
|
+
let collector = useToArray();
|
|
438
|
+
this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
|
|
439
|
+
return {
|
|
440
|
+
element: element,
|
|
441
|
+
index: BigInt(index)
|
|
442
|
+
};
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
let collector = useToArray();
|
|
447
|
+
this.buffer = collector.collect(argument1).map((element, index) => {
|
|
448
|
+
return {
|
|
449
|
+
element: element,
|
|
450
|
+
index: BigInt(index)
|
|
451
|
+
};
|
|
452
|
+
}).sort((a, b) => {
|
|
453
|
+
return Number(a.index - b.index);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
Object.defineProperties(this, {
|
|
457
|
+
"OrderedCollectable": {
|
|
458
|
+
value: OrderedCollectableSymbol,
|
|
459
|
+
writable: false,
|
|
460
|
+
enumerable: false,
|
|
461
|
+
configurable: false
|
|
462
|
+
},
|
|
463
|
+
"buffer": {
|
|
464
|
+
value: this.buffer,
|
|
465
|
+
writable: false,
|
|
466
|
+
enumerable: false,
|
|
467
|
+
configurable: false
|
|
468
|
+
}
|
|
242
469
|
});
|
|
243
|
-
|
|
470
|
+
Object.freeze(this);
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
throw new Error("Uncaught error on creating buffer.");
|
|
244
474
|
}
|
|
245
|
-
}
|
|
246
|
-
else if (isFunction(argument1)) {
|
|
247
|
-
let generator = argument1;
|
|
248
|
-
generator((element, index) => {
|
|
249
|
-
buffer.push({
|
|
250
|
-
index: index,
|
|
251
|
-
value: element
|
|
252
|
-
});
|
|
253
|
-
}, () => false);
|
|
254
475
|
}
|
|
255
476
|
else {
|
|
256
|
-
throw new TypeError("
|
|
477
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
257
478
|
}
|
|
258
|
-
buffer.map((indexed, _index, array) => {
|
|
259
|
-
let length = BigInt(array.length);
|
|
260
|
-
return {
|
|
261
|
-
index: ((indexed.index % length) + length) % length,
|
|
262
|
-
value: indexed.value
|
|
263
|
-
};
|
|
264
|
-
}).sort((a, b) => {
|
|
265
|
-
if (isFunction(argument2)) {
|
|
266
|
-
let comparator = argument2;
|
|
267
|
-
return comparator(a.value, b.value);
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
return useCompare(a.index, b.index);
|
|
271
|
-
}
|
|
272
|
-
}).forEach((indexed) => {
|
|
273
|
-
this.ordered.push(indexed);
|
|
274
|
-
});
|
|
275
479
|
}
|
|
276
|
-
|
|
277
|
-
|
|
480
|
+
*[Symbol.iterator]() {
|
|
481
|
+
try {
|
|
482
|
+
let collector = useToGeneratorFunction();
|
|
483
|
+
yield* collector.collect(this.source());
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
throw new Error("Uncaught error on Generator.");
|
|
487
|
+
}
|
|
278
488
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
constructor(parameter, comparator) {
|
|
284
|
-
if (isIterable(parameter)) {
|
|
285
|
-
if (isFunction(comparator)) {
|
|
286
|
-
super(parameter, comparator);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
super(parameter);
|
|
290
|
-
}
|
|
489
|
+
async *[Symbol.asyncIterator]() {
|
|
490
|
+
try {
|
|
491
|
+
let collector = useToAsyncGeneratorFunction();
|
|
492
|
+
yield* collector.collect(this.source());
|
|
291
493
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
super(parameter, comparator);
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
super(parameter);
|
|
298
|
-
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
299
496
|
}
|
|
300
497
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (window.length > 0) {
|
|
310
|
-
windows.push(window);
|
|
498
|
+
source() {
|
|
499
|
+
try {
|
|
500
|
+
return (accept, interrupt) => {
|
|
501
|
+
for (let indexed of this.buffer) {
|
|
502
|
+
if (interrupt(indexed.element, indexed.index)) {
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
accept(indexed.element, indexed.index);
|
|
311
506
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
throw new Error("Uncaught error on creating source.");
|
|
315
511
|
}
|
|
316
|
-
throw new RangeError("Invalid arguments.");
|
|
317
512
|
}
|
|
318
|
-
|
|
319
|
-
return this.
|
|
513
|
+
isEmpty() {
|
|
514
|
+
return this.buffer.length === 0;
|
|
320
515
|
}
|
|
321
516
|
}
|
|
322
517
|
;
|
|
518
|
+
Object.freeze(OrderedCollectable);
|
|
519
|
+
Object.freeze(OrderedCollectable.prototype);
|
|
520
|
+
Object.freeze(Object.getPrototypeOf(OrderedCollectable.prototype));
|