semantic-typescript 0.6.0 → 0.7.1
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/asynchronous/collector.d.ts +62 -58
- package/dist/asynchronous/collector.js +16 -5
- package/dist/asynchronous/semantic.d.ts +6 -2
- package/dist/asynchronous/semantic.js +19 -6
- package/dist/factory.d.ts +32 -71
- package/dist/factory.js +192 -603
- package/dist/guard.d.ts +0 -3
- package/dist/guard.js +0 -19
- package/dist/hash.js +3 -0
- package/dist/hook.d.ts +6 -1
- package/dist/hook.js +20 -3
- package/dist/synchronous/collector.d.ts +8 -4
- package/dist/synchronous/collector.js +74 -59
- package/dist/synchronous/semantic.d.ts +31 -23
- package/dist/synchronous/semantic.js +218 -286
- package/package.json +3 -2
- package/readme.cn.md +267 -214
- package/readme.de.md +225 -172
- package/readme.es.md +229 -170
- package/readme.fr.md +233 -170
- package/readme.jp.md +232 -169
- package/readme.kr.md +227 -169
- package/readme.md +270 -214
- package/readme.ru.md +231 -169
- package/readme.tw.md +225 -172
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { useSynchronousAnyMatch, useSynchronousAllMatch, useSynchronousCollect, useSynchronousCount, useSynchronousError, useSynchronousFindAny, useSynchronousFindAt, useSynchronousFindFirst, useSynchronousFindLast, useSynchronousFindMaximum, useSynchronousFindMinimum, useSynchronousForEach, useSynchronousGroup, useSynchronousGroupBy, useSynchronousJoin, useSynchronousLog, useSynchronousNoneMatch, useSynchronousPartition, useSynchronousPartitionBy, useSynchronousReduce, useSynchronousToArray, useSynchronousToMap, useSynchronousToSet, useSynchronousWrite, useSynchronousFrequency, useSynchronousBigIntAverage, useSynchronousBigIntMedian, useSynchronousBigIntMode, useSynchronousBigIntSummate, useSynchronousBigIntVariance, useSynchronousNumericAverage, useSynchronousNumericMedian, useSynchronousNumericMode, useSynchronousNumericStandardDeviation, useSynchronousNumericSummate, useSynchronousNumericVariance
|
|
2
|
-
import { isFunction, isSynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isSynchronousCollectable,
|
|
1
|
+
import { useSynchronousAnyMatch, useSynchronousAllMatch, useSynchronousCollect, useSynchronousCount, useSynchronousError, useSynchronousFindAny, useSynchronousFindAt, useSynchronousFindFirst, useSynchronousFindLast, useSynchronousFindMaximum, useSynchronousFindMinimum, useSynchronousForEach, useSynchronousGroup, useSynchronousGroupBy, useSynchronousJoin, useSynchronousLog, useSynchronousNoneMatch, useSynchronousPartition, useSynchronousPartitionBy, useSynchronousReduce, useSynchronousToArray, useSynchronousToMap, useSynchronousToSet, useSynchronousWrite, useSynchronousFrequency, useSynchronousBigIntAverage, useSynchronousBigIntMedian, useSynchronousBigIntMode, useSynchronousBigIntSummate, useSynchronousBigIntVariance, useSynchronousNumericAverage, useSynchronousNumericMedian, useSynchronousNumericMode, useSynchronousNumericStandardDeviation, useSynchronousNumericSummate, useSynchronousNumericVariance } from "./collector";
|
|
2
|
+
import { isFunction, isSynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isSynchronousCollectable, isSynchronousCollector } from "../guard";
|
|
3
3
|
import { useHash } from "../hash";
|
|
4
4
|
import { useCompare, useToBigInt, useToNumber } from "../hook";
|
|
5
|
-
import { SynchronousBigIntStatisticsSymbol, SynchronousCollectableSymbol, SynchronousNumericStatisticsSymbol,
|
|
6
|
-
import { invalidate, validate
|
|
5
|
+
import { SynchronousOrderedCollectableSymbol, SynchronousBigIntStatisticsSymbol, SynchronousCollectableSymbol, SynchronousNumericStatisticsSymbol, SynchronousSemanticSymbol, SynchronousWindowCollectableSymbol, SynchronousUnorderedCollectableSymbol, SynchronousStatisticsSymbol } from "../symbol";
|
|
6
|
+
import { invalidate, validate } from "../utility";
|
|
7
|
+
import { SynchronousCollector } from "./collector";
|
|
7
8
|
export class SynchronousSemantic {
|
|
8
9
|
generator;
|
|
9
10
|
SynchronousSemantic = SynchronousSemanticSymbol;
|
|
11
|
+
[Symbol.toStringTag] = "SynchronousSemantic";
|
|
10
12
|
constructor(generator) {
|
|
11
13
|
if (isFunction(generator)) {
|
|
12
14
|
this.generator = generator;
|
|
@@ -31,21 +33,22 @@ export class SynchronousSemantic {
|
|
|
31
33
|
}
|
|
32
34
|
concat(argument) {
|
|
33
35
|
if (isSynchronousSemantic(argument)) {
|
|
34
|
-
let other = argument;
|
|
35
36
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
36
37
|
try {
|
|
38
|
+
let other = argument;
|
|
39
|
+
let generator = other.source();
|
|
37
40
|
let count = 0n;
|
|
38
|
-
this.generator((element
|
|
39
|
-
accept(element,
|
|
41
|
+
this.generator((element) => {
|
|
42
|
+
accept(element, count);
|
|
40
43
|
count++;
|
|
41
44
|
}, interrupt);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
generator((element) => {
|
|
46
|
+
accept(element, count);
|
|
47
|
+
count++;
|
|
45
48
|
}, interrupt);
|
|
46
49
|
}
|
|
47
50
|
catch (error) {
|
|
48
|
-
throw
|
|
51
|
+
throw error;
|
|
49
52
|
}
|
|
50
53
|
});
|
|
51
54
|
}
|
|
@@ -64,7 +67,7 @@ export class SynchronousSemantic {
|
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
catch (error) {
|
|
67
|
-
throw
|
|
70
|
+
throw error;
|
|
68
71
|
}
|
|
69
72
|
});
|
|
70
73
|
}
|
|
@@ -84,7 +87,7 @@ export class SynchronousSemantic {
|
|
|
84
87
|
}, interrupt);
|
|
85
88
|
}
|
|
86
89
|
catch (error) {
|
|
87
|
-
throw
|
|
90
|
+
throw error;
|
|
88
91
|
}
|
|
89
92
|
});
|
|
90
93
|
}
|
|
@@ -106,7 +109,7 @@ export class SynchronousSemantic {
|
|
|
106
109
|
}, interrupt);
|
|
107
110
|
}
|
|
108
111
|
catch (error) {
|
|
109
|
-
throw
|
|
112
|
+
throw error;
|
|
110
113
|
}
|
|
111
114
|
});
|
|
112
115
|
}
|
|
@@ -123,7 +126,7 @@ export class SynchronousSemantic {
|
|
|
123
126
|
}, interrupt);
|
|
124
127
|
}
|
|
125
128
|
catch (error) {
|
|
126
|
-
throw
|
|
129
|
+
throw error;
|
|
127
130
|
}
|
|
128
131
|
});
|
|
129
132
|
}
|
|
@@ -154,7 +157,7 @@ export class SynchronousSemantic {
|
|
|
154
157
|
}, (element) => interrupt(element, count) || stop);
|
|
155
158
|
}
|
|
156
159
|
catch (error) {
|
|
157
|
-
throw
|
|
160
|
+
throw error;
|
|
158
161
|
}
|
|
159
162
|
});
|
|
160
163
|
}
|
|
@@ -167,16 +170,16 @@ export class SynchronousSemantic {
|
|
|
167
170
|
let count = 0n;
|
|
168
171
|
let stop = false;
|
|
169
172
|
this.generator((element, index) => {
|
|
170
|
-
let
|
|
171
|
-
if (isIterable(
|
|
172
|
-
for (let subElement of
|
|
173
|
+
let transform = mapper(element, index);
|
|
174
|
+
if (isIterable(transform)) {
|
|
175
|
+
for (let subElement of transform) {
|
|
173
176
|
accept(subElement, count);
|
|
174
177
|
stop = stop || interrupt(subElement, count);
|
|
175
178
|
count++;
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
|
-
else if (isSynchronousSemantic(
|
|
179
|
-
|
|
181
|
+
else if (isSynchronousSemantic(transform)) {
|
|
182
|
+
transform.source()((subElement) => {
|
|
180
183
|
accept(subElement, count);
|
|
181
184
|
stop = stop || interrupt(subElement, count);
|
|
182
185
|
count++;
|
|
@@ -185,44 +188,44 @@ export class SynchronousSemantic {
|
|
|
185
188
|
}, () => stop);
|
|
186
189
|
}
|
|
187
190
|
catch (error) {
|
|
188
|
-
throw
|
|
191
|
+
throw error;
|
|
189
192
|
}
|
|
190
193
|
});
|
|
191
194
|
}
|
|
192
195
|
throw new TypeError("Invalid arguments.");
|
|
193
196
|
}
|
|
194
|
-
limit(
|
|
195
|
-
if (isNumber(
|
|
196
|
-
let limit = BigInt(
|
|
197
|
+
limit(argument) {
|
|
198
|
+
if (isNumber(argument)) {
|
|
199
|
+
let limit = BigInt(argument);
|
|
197
200
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
198
201
|
try {
|
|
199
202
|
let count = 0n;
|
|
200
|
-
this.generator((element
|
|
203
|
+
this.generator((element) => {
|
|
201
204
|
if (count < limit) {
|
|
202
|
-
accept(element,
|
|
205
|
+
accept(element, count);
|
|
203
206
|
count++;
|
|
204
207
|
}
|
|
205
|
-
}, (element) => interrupt(element,
|
|
208
|
+
}, (element, index) => interrupt(element, index) || count >= limit);
|
|
206
209
|
}
|
|
207
210
|
catch (error) {
|
|
208
|
-
throw
|
|
211
|
+
throw error;
|
|
209
212
|
}
|
|
210
213
|
});
|
|
211
214
|
}
|
|
212
|
-
if (isBigInt(
|
|
213
|
-
let limit =
|
|
215
|
+
if (isBigInt(argument)) {
|
|
216
|
+
let limit = argument;
|
|
214
217
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
215
218
|
try {
|
|
216
219
|
let count = 0n;
|
|
217
|
-
this.generator((element
|
|
220
|
+
this.generator((element) => {
|
|
218
221
|
if (count < limit) {
|
|
219
|
-
accept(element,
|
|
222
|
+
accept(element, count);
|
|
220
223
|
count++;
|
|
221
224
|
}
|
|
222
|
-
}, (element) => interrupt(element,
|
|
225
|
+
}, (element, index) => interrupt(element, index) || count >= limit);
|
|
223
226
|
}
|
|
224
227
|
catch (error) {
|
|
225
|
-
throw
|
|
228
|
+
throw error;
|
|
226
229
|
}
|
|
227
230
|
});
|
|
228
231
|
}
|
|
@@ -240,7 +243,7 @@ export class SynchronousSemantic {
|
|
|
240
243
|
}, () => stop);
|
|
241
244
|
}
|
|
242
245
|
catch (error) {
|
|
243
|
-
throw
|
|
246
|
+
throw error;
|
|
244
247
|
}
|
|
245
248
|
});
|
|
246
249
|
}
|
|
@@ -256,7 +259,7 @@ export class SynchronousSemantic {
|
|
|
256
259
|
}, interrupt);
|
|
257
260
|
}
|
|
258
261
|
catch (error) {
|
|
259
|
-
throw
|
|
262
|
+
throw error;
|
|
260
263
|
}
|
|
261
264
|
});
|
|
262
265
|
}
|
|
@@ -271,7 +274,7 @@ export class SynchronousSemantic {
|
|
|
271
274
|
}, interrupt);
|
|
272
275
|
}
|
|
273
276
|
catch (error) {
|
|
274
|
-
throw
|
|
277
|
+
throw error;
|
|
275
278
|
}
|
|
276
279
|
});
|
|
277
280
|
}
|
|
@@ -285,22 +288,22 @@ export class SynchronousSemantic {
|
|
|
285
288
|
}, interrupt);
|
|
286
289
|
}
|
|
287
290
|
catch (error) {
|
|
288
|
-
throw
|
|
291
|
+
throw error;
|
|
289
292
|
}
|
|
290
293
|
});
|
|
291
294
|
}
|
|
292
295
|
shuffle(mapper) {
|
|
293
296
|
if (isFunction(mapper)) {
|
|
294
|
-
|
|
295
|
-
|
|
297
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
298
|
+
try {
|
|
296
299
|
this.generator((element, index) => {
|
|
297
300
|
accept(element, mapper(element, index));
|
|
298
301
|
}, interrupt);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
304
307
|
}
|
|
305
308
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
306
309
|
try {
|
|
@@ -309,12 +312,13 @@ export class SynchronousSemantic {
|
|
|
309
312
|
}, interrupt);
|
|
310
313
|
}
|
|
311
314
|
catch (error) {
|
|
312
|
-
throw
|
|
315
|
+
throw error;
|
|
313
316
|
}
|
|
314
317
|
});
|
|
315
318
|
}
|
|
316
|
-
skip(
|
|
317
|
-
if (isNumber(
|
|
319
|
+
skip(argument) {
|
|
320
|
+
if (isNumber(argument)) {
|
|
321
|
+
let n = argument;
|
|
318
322
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
319
323
|
try {
|
|
320
324
|
let count = 0n;
|
|
@@ -329,11 +333,12 @@ export class SynchronousSemantic {
|
|
|
329
333
|
}, interrupt);
|
|
330
334
|
}
|
|
331
335
|
catch (error) {
|
|
332
|
-
throw
|
|
336
|
+
throw error;
|
|
333
337
|
}
|
|
334
338
|
});
|
|
335
339
|
}
|
|
336
|
-
if (isBigInt(
|
|
340
|
+
if (isBigInt(argument)) {
|
|
341
|
+
let n = argument;
|
|
337
342
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
338
343
|
try {
|
|
339
344
|
let count = 0n;
|
|
@@ -347,7 +352,7 @@ export class SynchronousSemantic {
|
|
|
347
352
|
}, interrupt);
|
|
348
353
|
}
|
|
349
354
|
catch (error) {
|
|
350
|
-
throw
|
|
355
|
+
throw error;
|
|
351
356
|
}
|
|
352
357
|
});
|
|
353
358
|
}
|
|
@@ -356,73 +361,64 @@ export class SynchronousSemantic {
|
|
|
356
361
|
source() {
|
|
357
362
|
return this.generator;
|
|
358
363
|
}
|
|
359
|
-
sorted(comparator) {
|
|
360
|
-
if (isFunction(comparator)) {
|
|
361
|
-
try {
|
|
362
|
-
return new SynchronousOrderedCollectable(this.generator, comparator);
|
|
363
|
-
}
|
|
364
|
-
catch (error) {
|
|
365
|
-
throw new Error("Uncaught error on sorted.");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
try {
|
|
369
|
-
return new SynchronousOrderedCollectable(this.generator, (a, b) => useCompare(a, b));
|
|
370
|
-
}
|
|
371
|
-
catch (error) {
|
|
372
|
-
throw new Error("Uncaught error on sorted.");
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
364
|
sub(start, end) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
365
|
+
if ((isNumber(start) && isNumber(end)) || (isBigInt(start) && isBigInt(end))) {
|
|
366
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
367
|
+
try {
|
|
368
|
+
let count = 0n;
|
|
369
|
+
let resolvedStart = useToBigInt(start);
|
|
370
|
+
let resolvedEnd = useToBigInt(end);
|
|
371
|
+
let minimum = resolvedStart < resolvedEnd ? resolvedStart : resolvedEnd;
|
|
372
|
+
let maximum = resolvedStart < resolvedEnd ? resolvedEnd : resolvedStart;
|
|
373
|
+
this.generator((element, index) => {
|
|
374
|
+
if (minimum <= count && count < maximum) {
|
|
383
375
|
accept(element, index);
|
|
376
|
+
count++;
|
|
384
377
|
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
}
|
|
378
|
+
}, (element, index) => count >= maximum || interrupt(element, index));
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
throw new TypeError("Invalid arguments.");
|
|
392
386
|
}
|
|
393
387
|
takeWhile(predicate) {
|
|
394
388
|
return new SynchronousSemantic((accept, interrupt) => {
|
|
395
389
|
try {
|
|
390
|
+
let stop = false;
|
|
396
391
|
this.generator((element, index) => {
|
|
397
|
-
if (
|
|
398
|
-
|
|
399
|
-
return;
|
|
392
|
+
if (predicate(element, index) && !stop) {
|
|
393
|
+
accept(element, index);
|
|
400
394
|
}
|
|
401
|
-
|
|
402
|
-
|
|
395
|
+
else {
|
|
396
|
+
stop = true;
|
|
397
|
+
}
|
|
398
|
+
}, (element, index) => stop || interrupt(element, index));
|
|
403
399
|
}
|
|
404
400
|
catch (error) {
|
|
405
|
-
throw
|
|
401
|
+
throw error;
|
|
406
402
|
}
|
|
407
403
|
});
|
|
408
404
|
}
|
|
409
|
-
|
|
405
|
+
toCollectable(mapper) {
|
|
410
406
|
if (isFunction(mapper)) {
|
|
411
407
|
try {
|
|
412
|
-
let
|
|
413
|
-
if (isSynchronousCollectable(
|
|
414
|
-
return
|
|
408
|
+
let SynchronousCollectable = mapper(this.generator);
|
|
409
|
+
if (isSynchronousCollectable(SynchronousCollectable)) {
|
|
410
|
+
return SynchronousCollectable;
|
|
415
411
|
}
|
|
416
412
|
}
|
|
417
413
|
catch (error) {
|
|
418
|
-
throw
|
|
414
|
+
throw error;
|
|
419
415
|
}
|
|
420
416
|
}
|
|
421
417
|
try {
|
|
422
418
|
return new SynchronousUnorderedCollectable(this.generator);
|
|
423
419
|
}
|
|
424
420
|
catch (error) {
|
|
425
|
-
throw
|
|
421
|
+
throw error;
|
|
426
422
|
}
|
|
427
423
|
}
|
|
428
424
|
toBigintStatistics() {
|
|
@@ -430,7 +426,7 @@ export class SynchronousSemantic {
|
|
|
430
426
|
return new SynchronousBigIntStatistics(this.generator);
|
|
431
427
|
}
|
|
432
428
|
catch (error) {
|
|
433
|
-
throw
|
|
429
|
+
throw error;
|
|
434
430
|
}
|
|
435
431
|
}
|
|
436
432
|
toNumericStatistics() {
|
|
@@ -438,7 +434,7 @@ export class SynchronousSemantic {
|
|
|
438
434
|
return new SynchronousNumericStatistics(this.generator);
|
|
439
435
|
}
|
|
440
436
|
catch (error) {
|
|
441
|
-
throw
|
|
437
|
+
throw error;
|
|
442
438
|
}
|
|
443
439
|
}
|
|
444
440
|
toOrdered() {
|
|
@@ -446,7 +442,7 @@ export class SynchronousSemantic {
|
|
|
446
442
|
return new SynchronousOrderedCollectable(this.generator);
|
|
447
443
|
}
|
|
448
444
|
catch (error) {
|
|
449
|
-
throw
|
|
445
|
+
throw error;
|
|
450
446
|
}
|
|
451
447
|
}
|
|
452
448
|
toUnordered() {
|
|
@@ -454,7 +450,7 @@ export class SynchronousSemantic {
|
|
|
454
450
|
return new SynchronousUnorderedCollectable(this.generator);
|
|
455
451
|
}
|
|
456
452
|
catch (error) {
|
|
457
|
-
throw
|
|
453
|
+
throw error;
|
|
458
454
|
}
|
|
459
455
|
}
|
|
460
456
|
toWindow() {
|
|
@@ -462,7 +458,7 @@ export class SynchronousSemantic {
|
|
|
462
458
|
return new SynchronousWindowCollectable(this.generator);
|
|
463
459
|
}
|
|
464
460
|
catch (error) {
|
|
465
|
-
throw
|
|
461
|
+
throw error;
|
|
466
462
|
}
|
|
467
463
|
}
|
|
468
464
|
translate(argument1) {
|
|
@@ -475,7 +471,7 @@ export class SynchronousSemantic {
|
|
|
475
471
|
}, interrupt);
|
|
476
472
|
}
|
|
477
473
|
catch (error) {
|
|
478
|
-
throw
|
|
474
|
+
throw error;
|
|
479
475
|
}
|
|
480
476
|
});
|
|
481
477
|
}
|
|
@@ -488,7 +484,7 @@ export class SynchronousSemantic {
|
|
|
488
484
|
}, interrupt);
|
|
489
485
|
}
|
|
490
486
|
catch (error) {
|
|
491
|
-
throw
|
|
487
|
+
throw error;
|
|
492
488
|
}
|
|
493
489
|
});
|
|
494
490
|
}
|
|
@@ -501,7 +497,7 @@ export class SynchronousSemantic {
|
|
|
501
497
|
}, interrupt);
|
|
502
498
|
}
|
|
503
499
|
catch (error) {
|
|
504
|
-
throw
|
|
500
|
+
throw error;
|
|
505
501
|
}
|
|
506
502
|
});
|
|
507
503
|
}
|
|
@@ -511,6 +507,7 @@ export class SynchronousSemantic {
|
|
|
511
507
|
;
|
|
512
508
|
export class SynchronousCollectable {
|
|
513
509
|
SynchronousCollectable = SynchronousCollectableSymbol;
|
|
510
|
+
[Symbol.toStringTag] = "SynchronousCollectable";
|
|
514
511
|
constructor() {
|
|
515
512
|
Object.defineProperty(this, "SynchronousCollectable", {
|
|
516
513
|
value: SynchronousCollectableSymbol,
|
|
@@ -519,42 +516,47 @@ export class SynchronousCollectable {
|
|
|
519
516
|
configurable: false
|
|
520
517
|
});
|
|
521
518
|
}
|
|
519
|
+
*[Symbol.iterator]() {
|
|
520
|
+
for (let element of this.toArray()) {
|
|
521
|
+
yield element;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
522
524
|
anyMatch(predicate) {
|
|
523
525
|
if (isFunction(predicate)) {
|
|
524
526
|
try {
|
|
525
|
-
return useSynchronousAnyMatch(predicate).collect(this);
|
|
527
|
+
return useSynchronousAnyMatch(predicate).collect(this.source());
|
|
526
528
|
}
|
|
527
529
|
catch (error) {
|
|
528
|
-
throw
|
|
530
|
+
throw error;
|
|
529
531
|
}
|
|
530
532
|
}
|
|
531
533
|
throw new TypeError("Predicate must be a function.");
|
|
532
534
|
}
|
|
533
535
|
allMatch(predicate) {
|
|
534
|
-
return useSynchronousAllMatch(predicate).collect(this);
|
|
536
|
+
return useSynchronousAllMatch(predicate).collect(this.source());
|
|
535
537
|
}
|
|
536
538
|
collect(argument1, argument2, argument3, argument4) {
|
|
537
539
|
try {
|
|
538
|
-
if (
|
|
540
|
+
if (isSynchronousCollector(argument1)) {
|
|
539
541
|
let collector = argument1;
|
|
540
|
-
return collector.collect(this);
|
|
542
|
+
return collector.collect(this.source());
|
|
541
543
|
}
|
|
542
544
|
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
543
545
|
let identity = argument1;
|
|
544
546
|
let accumulator = argument2;
|
|
545
547
|
let finisher = argument3;
|
|
546
|
-
return useSynchronousCollect(identity, accumulator, finisher).collect(this);
|
|
548
|
+
return useSynchronousCollect(identity, accumulator, finisher).collect(this.source());
|
|
547
549
|
}
|
|
548
550
|
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
549
551
|
let identity = argument1;
|
|
550
552
|
let interrupt = argument2;
|
|
551
553
|
let accumulator = argument3;
|
|
552
554
|
let finisher = argument4;
|
|
553
|
-
return useSynchronousCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
555
|
+
return useSynchronousCollect(identity, interrupt, accumulator, finisher).collect(this.source());
|
|
554
556
|
}
|
|
555
557
|
}
|
|
556
558
|
catch (error) {
|
|
557
|
-
throw
|
|
559
|
+
throw error;
|
|
558
560
|
}
|
|
559
561
|
throw new TypeError("Invalid arguments.");
|
|
560
562
|
}
|
|
@@ -567,7 +569,7 @@ export class SynchronousCollectable {
|
|
|
567
569
|
useSynchronousError().collect(this.source());
|
|
568
570
|
}
|
|
569
571
|
catch (error) {
|
|
570
|
-
throw
|
|
572
|
+
throw error;
|
|
571
573
|
}
|
|
572
574
|
}
|
|
573
575
|
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
@@ -576,7 +578,7 @@ export class SynchronousCollectable {
|
|
|
576
578
|
useSynchronousError(accumulator).collect(this.source());
|
|
577
579
|
}
|
|
578
580
|
catch (error) {
|
|
579
|
-
throw
|
|
581
|
+
throw error;
|
|
580
582
|
}
|
|
581
583
|
}
|
|
582
584
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
@@ -587,7 +589,7 @@ export class SynchronousCollectable {
|
|
|
587
589
|
useSynchronousError(prefix, accumulator, suffix).collect(this.source());
|
|
588
590
|
}
|
|
589
591
|
catch (error) {
|
|
590
|
-
throw
|
|
592
|
+
throw error;
|
|
591
593
|
}
|
|
592
594
|
}
|
|
593
595
|
else {
|
|
@@ -602,7 +604,7 @@ export class SynchronousCollectable {
|
|
|
602
604
|
return useSynchronousFindAny().collect(this.source());
|
|
603
605
|
}
|
|
604
606
|
catch (error) {
|
|
605
|
-
throw
|
|
607
|
+
throw error;
|
|
606
608
|
}
|
|
607
609
|
}
|
|
608
610
|
findAt(index) {
|
|
@@ -611,7 +613,7 @@ export class SynchronousCollectable {
|
|
|
611
613
|
return useSynchronousFindAt(index).collect(this.source());
|
|
612
614
|
}
|
|
613
615
|
catch (error) {
|
|
614
|
-
throw
|
|
616
|
+
throw error;
|
|
615
617
|
}
|
|
616
618
|
}
|
|
617
619
|
else if (isNumber(index)) {
|
|
@@ -619,7 +621,7 @@ export class SynchronousCollectable {
|
|
|
619
621
|
return useSynchronousFindAt(index).collect(this.source());
|
|
620
622
|
}
|
|
621
623
|
catch (error) {
|
|
622
|
-
throw
|
|
624
|
+
throw error;
|
|
623
625
|
}
|
|
624
626
|
}
|
|
625
627
|
throw new TypeError("Index must be a bigint.");
|
|
@@ -629,7 +631,7 @@ export class SynchronousCollectable {
|
|
|
629
631
|
return useSynchronousFindFirst().collect(this.source());
|
|
630
632
|
}
|
|
631
633
|
catch (error) {
|
|
632
|
-
throw
|
|
634
|
+
throw error;
|
|
633
635
|
}
|
|
634
636
|
}
|
|
635
637
|
findLast() {
|
|
@@ -637,7 +639,7 @@ export class SynchronousCollectable {
|
|
|
637
639
|
return useSynchronousFindLast().collect(this.source());
|
|
638
640
|
}
|
|
639
641
|
catch (error) {
|
|
640
|
-
throw
|
|
642
|
+
throw error;
|
|
641
643
|
}
|
|
642
644
|
}
|
|
643
645
|
findMaximum(argument1) {
|
|
@@ -646,7 +648,7 @@ export class SynchronousCollectable {
|
|
|
646
648
|
return useSynchronousFindMaximum(comparator).collect(this.source());
|
|
647
649
|
}
|
|
648
650
|
catch (error) {
|
|
649
|
-
throw
|
|
651
|
+
throw error;
|
|
650
652
|
}
|
|
651
653
|
}
|
|
652
654
|
findMinimum(argument1) {
|
|
@@ -655,16 +657,16 @@ export class SynchronousCollectable {
|
|
|
655
657
|
return useSynchronousFindMinimum(comparator).collect(this.source());
|
|
656
658
|
}
|
|
657
659
|
catch (error) {
|
|
658
|
-
throw
|
|
660
|
+
throw error;
|
|
659
661
|
}
|
|
660
662
|
}
|
|
661
663
|
forEach(action) {
|
|
662
664
|
if (isFunction(action)) {
|
|
663
665
|
try {
|
|
664
|
-
useSynchronousForEach(action).collect(this);
|
|
666
|
+
useSynchronousForEach(action).collect(this.source());
|
|
665
667
|
}
|
|
666
668
|
catch (error) {
|
|
667
|
-
throw
|
|
669
|
+
throw error;
|
|
668
670
|
}
|
|
669
671
|
}
|
|
670
672
|
else {
|
|
@@ -677,7 +679,7 @@ export class SynchronousCollectable {
|
|
|
677
679
|
return useSynchronousGroup(classifier).collect(this.source());
|
|
678
680
|
}
|
|
679
681
|
catch (error) {
|
|
680
|
-
throw
|
|
682
|
+
throw error;
|
|
681
683
|
}
|
|
682
684
|
}
|
|
683
685
|
throw new TypeError("Classifier must be a function.");
|
|
@@ -688,7 +690,7 @@ export class SynchronousCollectable {
|
|
|
688
690
|
return useSynchronousGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
689
691
|
}
|
|
690
692
|
catch (error) {
|
|
691
|
-
throw
|
|
693
|
+
throw error;
|
|
692
694
|
}
|
|
693
695
|
}
|
|
694
696
|
throw new TypeError("Key and value extractors must be functions.");
|
|
@@ -699,7 +701,7 @@ export class SynchronousCollectable {
|
|
|
699
701
|
return useSynchronousJoin().collect(this.source());
|
|
700
702
|
}
|
|
701
703
|
catch (error) {
|
|
702
|
-
throw
|
|
704
|
+
throw error;
|
|
703
705
|
}
|
|
704
706
|
}
|
|
705
707
|
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
@@ -708,7 +710,7 @@ export class SynchronousCollectable {
|
|
|
708
710
|
return useSynchronousJoin(delimiter).collect(this.source());
|
|
709
711
|
}
|
|
710
712
|
catch (error) {
|
|
711
|
-
throw
|
|
713
|
+
throw error;
|
|
712
714
|
}
|
|
713
715
|
}
|
|
714
716
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
@@ -719,7 +721,7 @@ export class SynchronousCollectable {
|
|
|
719
721
|
return useSynchronousJoin(prefix, accumulator, suffix).collect(this.source());
|
|
720
722
|
}
|
|
721
723
|
catch (error) {
|
|
722
|
-
throw
|
|
724
|
+
throw error;
|
|
723
725
|
}
|
|
724
726
|
}
|
|
725
727
|
else if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
@@ -730,7 +732,7 @@ export class SynchronousCollectable {
|
|
|
730
732
|
return useSynchronousJoin(prefix, delimiter, suffix).collect(this.source());
|
|
731
733
|
}
|
|
732
734
|
catch (error) {
|
|
733
|
-
throw
|
|
735
|
+
throw error;
|
|
734
736
|
}
|
|
735
737
|
}
|
|
736
738
|
throw new TypeError("Invalid arguments.");
|
|
@@ -742,7 +744,7 @@ export class SynchronousCollectable {
|
|
|
742
744
|
useSynchronousLog(accumulator).collect(this.source());
|
|
743
745
|
}
|
|
744
746
|
catch (error) {
|
|
745
|
-
throw
|
|
747
|
+
throw error;
|
|
746
748
|
}
|
|
747
749
|
}
|
|
748
750
|
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
@@ -753,7 +755,7 @@ export class SynchronousCollectable {
|
|
|
753
755
|
useSynchronousLog(prefix, accumulator, suffix).collect(this.source());
|
|
754
756
|
}
|
|
755
757
|
catch (error) {
|
|
756
|
-
throw
|
|
758
|
+
throw error;
|
|
757
759
|
}
|
|
758
760
|
}
|
|
759
761
|
else {
|
|
@@ -761,7 +763,7 @@ export class SynchronousCollectable {
|
|
|
761
763
|
useSynchronousLog().collect(this.source());
|
|
762
764
|
}
|
|
763
765
|
catch (error) {
|
|
764
|
-
throw
|
|
766
|
+
throw error;
|
|
765
767
|
}
|
|
766
768
|
}
|
|
767
769
|
}
|
|
@@ -771,7 +773,7 @@ export class SynchronousCollectable {
|
|
|
771
773
|
return useSynchronousNoneMatch(predicate).collect(this.source());
|
|
772
774
|
}
|
|
773
775
|
catch (error) {
|
|
774
|
-
throw
|
|
776
|
+
throw error;
|
|
775
777
|
}
|
|
776
778
|
}
|
|
777
779
|
throw new TypeError("Predicate must be a function.");
|
|
@@ -782,7 +784,7 @@ export class SynchronousCollectable {
|
|
|
782
784
|
return useSynchronousPartition(count).collect(this.source());
|
|
783
785
|
}
|
|
784
786
|
catch (error) {
|
|
785
|
-
throw
|
|
787
|
+
throw error;
|
|
786
788
|
}
|
|
787
789
|
}
|
|
788
790
|
throw new TypeError("Count must be a BigInt.");
|
|
@@ -794,11 +796,14 @@ export class SynchronousCollectable {
|
|
|
794
796
|
return collector.collect(this.source());
|
|
795
797
|
}
|
|
796
798
|
catch (error) {
|
|
797
|
-
throw
|
|
799
|
+
throw error;
|
|
798
800
|
}
|
|
799
801
|
}
|
|
800
802
|
throw new TypeError("Classifier must be a function.");
|
|
801
803
|
}
|
|
804
|
+
pipe(conversion) {
|
|
805
|
+
return conversion(this.source());
|
|
806
|
+
}
|
|
802
807
|
reduce(argument1, argument2, argument3) {
|
|
803
808
|
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
804
809
|
try {
|
|
@@ -806,7 +811,7 @@ export class SynchronousCollectable {
|
|
|
806
811
|
return useSynchronousReduce(accumulator).collect(this.source());
|
|
807
812
|
}
|
|
808
813
|
catch (error) {
|
|
809
|
-
throw
|
|
814
|
+
throw error;
|
|
810
815
|
}
|
|
811
816
|
}
|
|
812
817
|
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
@@ -816,7 +821,7 @@ export class SynchronousCollectable {
|
|
|
816
821
|
return useSynchronousReduce(identity, accumulator).collect(this.source());
|
|
817
822
|
}
|
|
818
823
|
catch (error) {
|
|
819
|
-
throw
|
|
824
|
+
throw error;
|
|
820
825
|
}
|
|
821
826
|
}
|
|
822
827
|
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
@@ -827,7 +832,7 @@ export class SynchronousCollectable {
|
|
|
827
832
|
return useSynchronousReduce(identity, accumulator, finisher).collect(this.source());
|
|
828
833
|
}
|
|
829
834
|
catch (error) {
|
|
830
|
-
throw
|
|
835
|
+
throw error;
|
|
831
836
|
}
|
|
832
837
|
}
|
|
833
838
|
else {
|
|
@@ -841,7 +846,7 @@ export class SynchronousCollectable {
|
|
|
841
846
|
return new SynchronousSemantic(source);
|
|
842
847
|
}
|
|
843
848
|
catch (error) {
|
|
844
|
-
throw
|
|
849
|
+
throw error;
|
|
845
850
|
}
|
|
846
851
|
}
|
|
847
852
|
else {
|
|
@@ -853,7 +858,7 @@ export class SynchronousCollectable {
|
|
|
853
858
|
return useSynchronousToArray().collect(this.source());
|
|
854
859
|
}
|
|
855
860
|
catch (error) {
|
|
856
|
-
throw
|
|
861
|
+
throw error;
|
|
857
862
|
}
|
|
858
863
|
}
|
|
859
864
|
toMap(keyExtractor, valueExtractor = (element) => element) {
|
|
@@ -861,7 +866,7 @@ export class SynchronousCollectable {
|
|
|
861
866
|
return useSynchronousToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
862
867
|
}
|
|
863
868
|
catch (error) {
|
|
864
|
-
throw
|
|
869
|
+
throw error;
|
|
865
870
|
}
|
|
866
871
|
}
|
|
867
872
|
toSet() {
|
|
@@ -869,7 +874,7 @@ export class SynchronousCollectable {
|
|
|
869
874
|
return useSynchronousToSet().collect(this.source());
|
|
870
875
|
}
|
|
871
876
|
catch (error) {
|
|
872
|
-
throw
|
|
877
|
+
throw error;
|
|
873
878
|
}
|
|
874
879
|
}
|
|
875
880
|
write(argument1, argument2) {
|
|
@@ -885,7 +890,7 @@ export class SynchronousCollectable {
|
|
|
885
890
|
}
|
|
886
891
|
}
|
|
887
892
|
catch (error) {
|
|
888
|
-
throw
|
|
893
|
+
throw error;
|
|
889
894
|
}
|
|
890
895
|
}
|
|
891
896
|
throw new TypeError("Invalid arguments.");
|
|
@@ -893,31 +898,37 @@ export class SynchronousCollectable {
|
|
|
893
898
|
}
|
|
894
899
|
;
|
|
895
900
|
export class SynchronousOrderedCollectable extends SynchronousCollectable {
|
|
896
|
-
|
|
897
|
-
buffer;
|
|
901
|
+
OrderedCollectable = SynchronousOrderedCollectableSymbol;
|
|
902
|
+
buffer = [];
|
|
903
|
+
[Symbol.toStringTag] = "SynchronousOrderedCollectable";
|
|
898
904
|
constructor(argument1, argument2) {
|
|
899
905
|
super();
|
|
900
906
|
if (isFunction(argument1)) {
|
|
901
907
|
try {
|
|
902
908
|
if (isFunction(argument2)) {
|
|
903
909
|
let collector = useSynchronousToArray();
|
|
904
|
-
|
|
910
|
+
let generator = argument1;
|
|
911
|
+
let comparator = argument2;
|
|
912
|
+
this.buffer = collector.collect(generator).sort(comparator).map((element, index) => {
|
|
905
913
|
return {
|
|
906
914
|
element: element,
|
|
907
915
|
index: BigInt(index)
|
|
908
916
|
};
|
|
909
917
|
});
|
|
918
|
+
Object.freeze(this.buffer);
|
|
910
919
|
}
|
|
911
920
|
else {
|
|
912
921
|
let collector = useSynchronousToArray();
|
|
913
|
-
|
|
922
|
+
let generator = argument1;
|
|
923
|
+
this.buffer = collector.collect(generator).map((element, index, array) => {
|
|
914
924
|
return {
|
|
915
925
|
element: element,
|
|
916
|
-
index: BigInt(index)
|
|
926
|
+
index: BigInt(((index % array.length) + array.length) % array.length)
|
|
917
927
|
};
|
|
918
928
|
}).sort((a, b) => {
|
|
919
929
|
return Number(a.index - b.index);
|
|
920
930
|
});
|
|
931
|
+
Object.freeze(this.buffer);
|
|
921
932
|
}
|
|
922
933
|
Object.defineProperties(this, {
|
|
923
934
|
"SynchronousOrderedCollectable": {
|
|
@@ -943,47 +954,35 @@ export class SynchronousOrderedCollectable extends SynchronousCollectable {
|
|
|
943
954
|
}
|
|
944
955
|
}
|
|
945
956
|
*[Symbol.iterator]() {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
yield indexed.element;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
catch (error) {
|
|
952
|
-
throw new Error("Uncaught error on Generator.");
|
|
957
|
+
for (let { element } of this.buffer) {
|
|
958
|
+
yield element;
|
|
953
959
|
}
|
|
954
960
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
yield indexed.element;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
catch (error) {
|
|
962
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
963
|
-
}
|
|
961
|
+
allMatch(predicate) {
|
|
962
|
+
let collector = SynchronousCollector.shortable(() => false, (element, index, accumulator) => predicate(element.element, index) && accumulator, (accumulator, element, index) => predicate(element.element, index) && accumulator, (result) => result);
|
|
963
|
+
return collector.collect(this.buffer);
|
|
964
964
|
}
|
|
965
965
|
source() {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
break;
|
|
971
|
-
}
|
|
972
|
-
accept(indexed.element, indexed.index);
|
|
966
|
+
return (accept, interrupt) => {
|
|
967
|
+
for (let { element, index } of this.buffer) {
|
|
968
|
+
if (interrupt(element, index)) {
|
|
969
|
+
break;
|
|
973
970
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
throw new Error("Uncaught error on creating source.");
|
|
978
|
-
}
|
|
971
|
+
accept(element, index);
|
|
972
|
+
}
|
|
973
|
+
};
|
|
979
974
|
}
|
|
980
975
|
isEmpty() {
|
|
981
976
|
return this.buffer.length === 0;
|
|
982
977
|
}
|
|
978
|
+
count() {
|
|
979
|
+
return BigInt(this.buffer.length);
|
|
980
|
+
}
|
|
983
981
|
}
|
|
984
982
|
;
|
|
985
983
|
export class SynchronousUnorderedCollectable extends SynchronousCollectable {
|
|
986
984
|
SynchronousUnorderedCollectable = SynchronousUnorderedCollectableSymbol;
|
|
985
|
+
[Symbol.toStringTag] = "SynchronousUnorderedCollectable";
|
|
987
986
|
buffer = new Map();
|
|
988
987
|
constructor(argument1) {
|
|
989
988
|
super();
|
|
@@ -992,6 +991,7 @@ export class SynchronousUnorderedCollectable extends SynchronousCollectable {
|
|
|
992
991
|
generator((element, index) => {
|
|
993
992
|
this.buffer.set(index, element);
|
|
994
993
|
}, () => false);
|
|
994
|
+
Object.freeze(this.buffer);
|
|
995
995
|
Object.defineProperties(this, {
|
|
996
996
|
"SynchronousUnorderedCollectable": {
|
|
997
997
|
value: SynchronousUnorderedCollectableSymbol,
|
|
@@ -1005,40 +1005,26 @@ export class SynchronousUnorderedCollectable extends SynchronousCollectable {
|
|
|
1005
1005
|
throw new TypeError("Source must be an iterable or a generator function.");
|
|
1006
1006
|
}
|
|
1007
1007
|
}
|
|
1008
|
+
*[Symbol.iterator]() {
|
|
1009
|
+
for (let [_index, element] of this.buffer) {
|
|
1010
|
+
yield element;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1008
1013
|
source() {
|
|
1009
1014
|
return (accept, interrupt) => {
|
|
1010
|
-
for (let [
|
|
1011
|
-
if (interrupt(element,
|
|
1015
|
+
for (let [_index, element] of this.buffer) {
|
|
1016
|
+
if (interrupt(element, _index)) {
|
|
1012
1017
|
break;
|
|
1013
1018
|
}
|
|
1014
|
-
accept(element,
|
|
1019
|
+
accept(element, _index);
|
|
1015
1020
|
}
|
|
1016
1021
|
};
|
|
1017
1022
|
}
|
|
1018
|
-
*[Symbol.iterator]() {
|
|
1019
|
-
try {
|
|
1020
|
-
for (let [_index, element] of this.buffer) {
|
|
1021
|
-
yield element;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
catch (error) {
|
|
1025
|
-
throw new Error("Uncaught error on Generator.");
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
async *[Symbol.asyncIterator]() {
|
|
1029
|
-
try {
|
|
1030
|
-
for (let [_index, element] of this.buffer) {
|
|
1031
|
-
yield element;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
catch (error) {
|
|
1035
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
1023
|
}
|
|
1039
1024
|
;
|
|
1040
1025
|
export class SynchronousStatistics extends SynchronousOrderedCollectable {
|
|
1041
1026
|
SynchronousStatistics = SynchronousStatisticsSymbol;
|
|
1027
|
+
[Symbol.toStringTag] = "SynchronousStatistics";
|
|
1042
1028
|
constructor(parameter, comparator) {
|
|
1043
1029
|
super(parameter, validate(comparator) ? comparator : useCompare);
|
|
1044
1030
|
Object.defineProperties(this, {
|
|
@@ -1051,28 +1037,10 @@ export class SynchronousStatistics extends SynchronousOrderedCollectable {
|
|
|
1051
1037
|
});
|
|
1052
1038
|
}
|
|
1053
1039
|
*[Symbol.iterator]() {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
yield indexed.element;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
catch (error) {
|
|
1060
|
-
throw new Error("Uncaught error on Generator.");
|
|
1040
|
+
for (let { element } of this.buffer) {
|
|
1041
|
+
yield element;
|
|
1061
1042
|
}
|
|
1062
1043
|
}
|
|
1063
|
-
async *[Symbol.asyncIterator]() {
|
|
1064
|
-
try {
|
|
1065
|
-
for (let indexed of this.buffer) {
|
|
1066
|
-
yield indexed.element;
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
catch (error) {
|
|
1070
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
count() {
|
|
1074
|
-
return BigInt(this.buffer.length);
|
|
1075
|
-
}
|
|
1076
1044
|
frequency() {
|
|
1077
1045
|
return useSynchronousFrequency().collect(this.source());
|
|
1078
1046
|
}
|
|
@@ -1080,6 +1048,7 @@ export class SynchronousStatistics extends SynchronousOrderedCollectable {
|
|
|
1080
1048
|
;
|
|
1081
1049
|
export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
1082
1050
|
BigIntStatistics = SynchronousBigIntStatisticsSymbol;
|
|
1051
|
+
[Symbol.toStringTag] = "SynchronousBigIntStatistics";
|
|
1083
1052
|
constructor(parameter, comparator) {
|
|
1084
1053
|
super(parameter, comparator || useCompare);
|
|
1085
1054
|
Object.defineProperties(this, {
|
|
@@ -1092,23 +1061,8 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1092
1061
|
});
|
|
1093
1062
|
}
|
|
1094
1063
|
*[Symbol.iterator]() {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
yield indexed.element;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
catch (error) {
|
|
1101
|
-
throw new Error("Uncaught error on Generator.");
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
async *[Symbol.asyncIterator]() {
|
|
1105
|
-
try {
|
|
1106
|
-
for (let indexed of this.buffer) {
|
|
1107
|
-
yield indexed.element;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
catch (error) {
|
|
1111
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1064
|
+
for (let { element } of this.buffer) {
|
|
1065
|
+
yield element;
|
|
1112
1066
|
}
|
|
1113
1067
|
}
|
|
1114
1068
|
average(argument1) {
|
|
@@ -1129,10 +1083,14 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1129
1083
|
}
|
|
1130
1084
|
try {
|
|
1131
1085
|
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1132
|
-
let
|
|
1133
|
-
let
|
|
1134
|
-
|
|
1135
|
-
|
|
1086
|
+
let minimum = this.findFirst();
|
|
1087
|
+
let maximum = this.findLast();
|
|
1088
|
+
return minimum.flatMap((minimum) => {
|
|
1089
|
+
return maximum.map((maximum) => {
|
|
1090
|
+
let difference = mapper(maximum) - mapper(minimum);
|
|
1091
|
+
return difference < 0n ? -difference : difference;
|
|
1092
|
+
});
|
|
1093
|
+
}).get(0n);
|
|
1136
1094
|
}
|
|
1137
1095
|
catch (error) {
|
|
1138
1096
|
throw new Error("Uncaught error on range.");
|
|
@@ -1212,7 +1170,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1212
1170
|
if (this.isEmpty()) {
|
|
1213
1171
|
return 0n;
|
|
1214
1172
|
}
|
|
1215
|
-
if (
|
|
1173
|
+
if (!isNumber(quantile) || quantile < 0 || quantile > 1) {
|
|
1216
1174
|
throw new RangeError("Invalid quantile.");
|
|
1217
1175
|
}
|
|
1218
1176
|
try {
|
|
@@ -1222,8 +1180,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1222
1180
|
if (index === count) {
|
|
1223
1181
|
index--;
|
|
1224
1182
|
}
|
|
1225
|
-
|
|
1226
|
-
return value;
|
|
1183
|
+
return this.findAt(index).map(mapper).get(0n);
|
|
1227
1184
|
}
|
|
1228
1185
|
catch (error) {
|
|
1229
1186
|
throw new Error("Uncaught error on quantile.");
|
|
@@ -1254,7 +1211,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1254
1211
|
if (standardDeviation === 0n) {
|
|
1255
1212
|
return 0n;
|
|
1256
1213
|
}
|
|
1257
|
-
let data = this.toArray().map(
|
|
1214
|
+
let data = (this.toArray()).map((element) => mapper(element));
|
|
1258
1215
|
let summate = 0n;
|
|
1259
1216
|
for (let value of data) {
|
|
1260
1217
|
let z = value - mean;
|
|
@@ -1277,7 +1234,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1277
1234
|
if (standardDeviation === 0n) {
|
|
1278
1235
|
return 0n;
|
|
1279
1236
|
}
|
|
1280
|
-
let data = this.toArray().map(
|
|
1237
|
+
let data = (this.toArray()).map((element) => mapper(element));
|
|
1281
1238
|
let summate = 0n;
|
|
1282
1239
|
let count = data.length;
|
|
1283
1240
|
for (let value of data) {
|
|
@@ -1294,6 +1251,7 @@ export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
|
1294
1251
|
;
|
|
1295
1252
|
export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
1296
1253
|
SynchronousNumericStatistics = SynchronousNumericStatisticsSymbol;
|
|
1254
|
+
[Symbol.toStringTag] = "SynchronousNumericStatistics";
|
|
1297
1255
|
constructor(parameter, comparator) {
|
|
1298
1256
|
super(parameter, comparator || useCompare);
|
|
1299
1257
|
Object.defineProperties(this, {
|
|
@@ -1306,23 +1264,8 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
|
1306
1264
|
});
|
|
1307
1265
|
}
|
|
1308
1266
|
*[Symbol.iterator]() {
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
yield indexed.element;
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
catch (error) {
|
|
1315
|
-
throw new Error("Uncaught error on Generator.");
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
async *[Symbol.asyncIterator]() {
|
|
1319
|
-
try {
|
|
1320
|
-
for (let indexed of this.buffer) {
|
|
1321
|
-
yield indexed.element;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
catch (error) {
|
|
1325
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1267
|
+
for (let { element } of this.buffer) {
|
|
1268
|
+
yield element;
|
|
1326
1269
|
}
|
|
1327
1270
|
}
|
|
1328
1271
|
average(mapper) {
|
|
@@ -1348,10 +1291,14 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
|
1348
1291
|
return 0;
|
|
1349
1292
|
}
|
|
1350
1293
|
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1351
|
-
let
|
|
1352
|
-
let
|
|
1353
|
-
|
|
1354
|
-
|
|
1294
|
+
let minimum = this.findFirst();
|
|
1295
|
+
let maximum = this.findLast();
|
|
1296
|
+
return minimum.flatMap((minimum) => {
|
|
1297
|
+
return maximum.map((maximum) => {
|
|
1298
|
+
let difference = mapper(maximum) - mapper(minimum);
|
|
1299
|
+
return difference < 0 ? -difference : difference;
|
|
1300
|
+
});
|
|
1301
|
+
}).get(0);
|
|
1355
1302
|
}
|
|
1356
1303
|
catch (error) {
|
|
1357
1304
|
throw new Error("Uncaught error on range.");
|
|
@@ -1440,8 +1387,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
|
1440
1387
|
if (index === count) {
|
|
1441
1388
|
index--;
|
|
1442
1389
|
}
|
|
1443
|
-
|
|
1444
|
-
return value;
|
|
1390
|
+
return this.findAt(index).map(mapper).get(0);
|
|
1445
1391
|
}
|
|
1446
1392
|
catch (error) {
|
|
1447
1393
|
throw new Error("Uncaught error on quantile.");
|
|
@@ -1472,7 +1418,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
|
1472
1418
|
if (standardDeviation === 0) {
|
|
1473
1419
|
return 0;
|
|
1474
1420
|
}
|
|
1475
|
-
let data = this.toArray().map(
|
|
1421
|
+
let data = (this.toArray()).map((element) => mapper(element));
|
|
1476
1422
|
let summate = 0;
|
|
1477
1423
|
for (let value of data) {
|
|
1478
1424
|
let z = (value - mean) / standardDeviation;
|
|
@@ -1495,7 +1441,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
|
1495
1441
|
if (standardDeviation === 0) {
|
|
1496
1442
|
return 0;
|
|
1497
1443
|
}
|
|
1498
|
-
let data = this.toArray().map(
|
|
1444
|
+
let data = (this.toArray()).map((element) => mapper(element));
|
|
1499
1445
|
let summate = 0;
|
|
1500
1446
|
for (let value of data) {
|
|
1501
1447
|
let z = (value - mean) / standardDeviation;
|
|
@@ -1511,6 +1457,7 @@ export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
|
1511
1457
|
;
|
|
1512
1458
|
export class SynchronousWindowCollectable extends SynchronousOrderedCollectable {
|
|
1513
1459
|
WindowCollectable = SynchronousWindowCollectableSymbol;
|
|
1460
|
+
[Symbol.toStringTag] = "SynchronousWindowCollectable";
|
|
1514
1461
|
constructor(parameter, comparator = useCompare) {
|
|
1515
1462
|
super(parameter, comparator);
|
|
1516
1463
|
Object.defineProperties(this, {
|
|
@@ -1523,23 +1470,8 @@ export class SynchronousWindowCollectable extends SynchronousOrderedCollectable
|
|
|
1523
1470
|
});
|
|
1524
1471
|
}
|
|
1525
1472
|
*[Symbol.iterator]() {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
yield indexed.element;
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
catch (error) {
|
|
1532
|
-
throw new Error("Uncaught error on Generator.");
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
async *[Symbol.asyncIterator]() {
|
|
1536
|
-
try {
|
|
1537
|
-
for (let indexed of this.buffer) {
|
|
1538
|
-
yield indexed.element;
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
catch (error) {
|
|
1542
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1473
|
+
for (let { element } of this.buffer) {
|
|
1474
|
+
yield element;
|
|
1543
1475
|
}
|
|
1544
1476
|
}
|
|
1545
1477
|
slide(size, step = 1n) {
|