semantic-typescript 0.5.3 → 0.6.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/dist/asynchronous/collector.d.ts +231 -0
- package/dist/asynchronous/collector.js +800 -0
- package/dist/asynchronous/semantic.d.ts +257 -0
- package/dist/asynchronous/semantic.js +1853 -0
- package/dist/factory.d.ts +71 -37
- package/dist/factory.js +443 -262
- package/dist/guard.d.ts +24 -14
- package/dist/guard.js +73 -19
- package/dist/hook.d.ts +6 -6
- package/dist/hook.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/optional.d.ts +2 -2
- package/dist/symbol.d.ts +19 -10
- package/dist/symbol.js +19 -10
- package/dist/synchronous/collector.d.ts +232 -0
- package/dist/{collector.js → synchronous/collector.js} +160 -151
- package/dist/{semantic.d.ts → synchronous/semantic.d.ts} +111 -120
- package/dist/{semantic.js → synchronous/semantic.js} +299 -337
- package/dist/utility.d.ts +7 -1
- package/dist/utility.js +1 -0
- package/package.json +1 -1
- package/readme.cn.md +158 -697
- package/readme.de.md +163 -432
- package/readme.es.md +163 -433
- package/readme.fr.md +162 -444
- package/readme.jp.md +162 -442
- package/readme.kr.md +161 -430
- package/readme.md +157 -1009
- package/readme.ru.md +161 -426
- package/readme.tw.md +161 -436
- package/dist/collector.d.ts +0 -236
- package/dist/main.d.ts +0 -1
- package/dist/main.js +0 -4
- package/dist/map.d.ts +0 -76
- package/dist/map.js +0 -245
- package/dist/node.d.ts +0 -182
- package/dist/node.js +0 -918
- package/dist/set.d.ts +0 -19
- package/dist/set.js +0 -65
- package/dist/tree.d.ts +0 -82
- package/dist/tree.js +0 -257
|
@@ -1,32 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useHash } from "
|
|
4
|
-
import { useCompare, useToBigInt, useToNumber } from "
|
|
5
|
-
import {
|
|
6
|
-
import { invalidate, validate } from "
|
|
7
|
-
export class
|
|
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, SynchronousCollector } from "./collector";
|
|
2
|
+
import { isFunction, isSynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isSynchronousCollectable, isAsynchronousCollector } from "../guard";
|
|
3
|
+
import { useHash } from "../hash";
|
|
4
|
+
import { useCompare, useToBigInt, useToNumber } from "../hook";
|
|
5
|
+
import { SynchronousBigIntStatisticsSymbol, SynchronousCollectableSymbol, SynchronousNumericStatisticsSymbol, SynchronousOrderedCollectableSymbol, SynchronousSemanticSymbol, SynchronousStatisticsSymbol, SynchronousUnorderedCollectableSymbol, SynchronousWindowCollectableSymbol } from "../symbol";
|
|
6
|
+
import { invalidate, validate, } from "../utility";
|
|
7
|
+
export class SynchronousSemantic {
|
|
8
8
|
generator;
|
|
9
|
-
|
|
9
|
+
SynchronousSemantic = SynchronousSemanticSymbol;
|
|
10
10
|
constructor(generator) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
if (isFunction(generator)) {
|
|
12
|
+
this.generator = generator;
|
|
13
|
+
Object.defineProperties(this, {
|
|
14
|
+
"SynchronousSemantic": {
|
|
15
|
+
value: SynchronousSemanticSymbol,
|
|
16
|
+
writable: false,
|
|
17
|
+
enumerable: false,
|
|
18
|
+
configurable: false
|
|
19
|
+
},
|
|
20
|
+
"generator": {
|
|
21
|
+
value: generator,
|
|
22
|
+
writable: false,
|
|
23
|
+
enumerable: false,
|
|
24
|
+
configurable: false
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new TypeError("Invalid arguments.");
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
|
-
concat(
|
|
28
|
-
if (
|
|
29
|
-
|
|
32
|
+
concat(argument) {
|
|
33
|
+
if (isSynchronousSemantic(argument)) {
|
|
34
|
+
let other = argument;
|
|
35
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
30
36
|
try {
|
|
31
37
|
let count = 0n;
|
|
32
38
|
this.generator((element, index) => {
|
|
@@ -43,8 +49,9 @@ export class Semantic {
|
|
|
43
49
|
}
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
|
-
if (isIterable(
|
|
47
|
-
|
|
52
|
+
if (isIterable(argument)) {
|
|
53
|
+
let other = argument;
|
|
54
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
48
55
|
try {
|
|
49
56
|
let count = 0n;
|
|
50
57
|
this.generator((element, index) => {
|
|
@@ -65,7 +72,7 @@ export class Semantic {
|
|
|
65
72
|
}
|
|
66
73
|
distinct(argument1) {
|
|
67
74
|
let keyExtractor = validate(argument1) ? argument1 : (element) => element;
|
|
68
|
-
return new
|
|
75
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
69
76
|
try {
|
|
70
77
|
let set = new Set();
|
|
71
78
|
this.generator((element, index) => {
|
|
@@ -83,18 +90,19 @@ export class Semantic {
|
|
|
83
90
|
}
|
|
84
91
|
dropWhile(predicate) {
|
|
85
92
|
if (isFunction(predicate)) {
|
|
86
|
-
return new
|
|
93
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
87
94
|
try {
|
|
88
|
-
let
|
|
95
|
+
let count = -1n;
|
|
89
96
|
this.generator((element, index) => {
|
|
90
|
-
if (
|
|
97
|
+
if (count === -1n) {
|
|
91
98
|
if (!predicate(element, index)) {
|
|
92
|
-
|
|
93
|
-
accept(element, index);
|
|
99
|
+
count++;
|
|
94
100
|
}
|
|
95
|
-
return;
|
|
96
101
|
}
|
|
97
|
-
|
|
102
|
+
else {
|
|
103
|
+
accept(element, count);
|
|
104
|
+
count++;
|
|
105
|
+
}
|
|
98
106
|
}, interrupt);
|
|
99
107
|
}
|
|
100
108
|
catch (error) {
|
|
@@ -106,7 +114,7 @@ export class Semantic {
|
|
|
106
114
|
}
|
|
107
115
|
filter(predicate) {
|
|
108
116
|
if (isFunction(predicate)) {
|
|
109
|
-
return new
|
|
117
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
110
118
|
try {
|
|
111
119
|
this.generator((element, index) => {
|
|
112
120
|
if (predicate(element, index)) {
|
|
@@ -123,7 +131,7 @@ export class Semantic {
|
|
|
123
131
|
}
|
|
124
132
|
flat(mapper) {
|
|
125
133
|
if (isFunction(mapper)) {
|
|
126
|
-
return new
|
|
134
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
127
135
|
try {
|
|
128
136
|
let count = 0n;
|
|
129
137
|
let stop = false;
|
|
@@ -136,7 +144,7 @@ export class Semantic {
|
|
|
136
144
|
count++;
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
|
-
else if (
|
|
147
|
+
else if (isSynchronousSemantic(result)) {
|
|
140
148
|
result.generator((subElement) => {
|
|
141
149
|
accept(subElement, count);
|
|
142
150
|
stop = stop || interrupt(subElement, count);
|
|
@@ -154,7 +162,7 @@ export class Semantic {
|
|
|
154
162
|
}
|
|
155
163
|
flatMap(mapper) {
|
|
156
164
|
if (isFunction(mapper)) {
|
|
157
|
-
return new
|
|
165
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
158
166
|
try {
|
|
159
167
|
let count = 0n;
|
|
160
168
|
let stop = false;
|
|
@@ -167,7 +175,7 @@ export class Semantic {
|
|
|
167
175
|
count++;
|
|
168
176
|
}
|
|
169
177
|
}
|
|
170
|
-
else if (
|
|
178
|
+
else if (isSynchronousSemantic(result)) {
|
|
171
179
|
result.generator((subElement) => {
|
|
172
180
|
accept(subElement, count);
|
|
173
181
|
stop = stop || interrupt(subElement, count);
|
|
@@ -186,7 +194,7 @@ export class Semantic {
|
|
|
186
194
|
limit(n) {
|
|
187
195
|
if (isNumber(n)) {
|
|
188
196
|
let limit = BigInt(n);
|
|
189
|
-
return new
|
|
197
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
190
198
|
try {
|
|
191
199
|
let count = 0n;
|
|
192
200
|
this.generator((element, index) => {
|
|
@@ -203,7 +211,7 @@ export class Semantic {
|
|
|
203
211
|
}
|
|
204
212
|
if (isBigInt(n)) {
|
|
205
213
|
let limit = n;
|
|
206
|
-
return new
|
|
214
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
207
215
|
try {
|
|
208
216
|
let count = 0n;
|
|
209
217
|
this.generator((element, index) => {
|
|
@@ -222,7 +230,7 @@ export class Semantic {
|
|
|
222
230
|
}
|
|
223
231
|
map(mapper) {
|
|
224
232
|
if (isFunction(mapper)) {
|
|
225
|
-
return new
|
|
233
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
226
234
|
try {
|
|
227
235
|
let stop = false;
|
|
228
236
|
this.generator((element, index) => {
|
|
@@ -240,7 +248,7 @@ export class Semantic {
|
|
|
240
248
|
}
|
|
241
249
|
peek(consumer) {
|
|
242
250
|
if (isFunction(consumer)) {
|
|
243
|
-
return new
|
|
251
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
244
252
|
try {
|
|
245
253
|
this.generator((element, index) => {
|
|
246
254
|
accept(element, index);
|
|
@@ -256,7 +264,7 @@ export class Semantic {
|
|
|
256
264
|
}
|
|
257
265
|
redirect(redirector) {
|
|
258
266
|
if (isFunction(redirector)) {
|
|
259
|
-
return new
|
|
267
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
260
268
|
try {
|
|
261
269
|
this.generator((element, index) => {
|
|
262
270
|
accept(element, redirector(element, index));
|
|
@@ -270,7 +278,7 @@ export class Semantic {
|
|
|
270
278
|
throw new TypeError("Invalid arguments.");
|
|
271
279
|
}
|
|
272
280
|
reverse() {
|
|
273
|
-
return new
|
|
281
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
274
282
|
try {
|
|
275
283
|
this.generator((element, index) => {
|
|
276
284
|
accept(element, -index);
|
|
@@ -284,7 +292,7 @@ export class Semantic {
|
|
|
284
292
|
shuffle(mapper) {
|
|
285
293
|
if (isFunction(mapper)) {
|
|
286
294
|
try {
|
|
287
|
-
return new
|
|
295
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
288
296
|
this.generator((element, index) => {
|
|
289
297
|
accept(element, mapper(element, index));
|
|
290
298
|
}, interrupt);
|
|
@@ -294,7 +302,7 @@ export class Semantic {
|
|
|
294
302
|
throw new Error("Uncaught error on shuffle.");
|
|
295
303
|
}
|
|
296
304
|
}
|
|
297
|
-
return new
|
|
305
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
298
306
|
try {
|
|
299
307
|
this.generator((element, index) => {
|
|
300
308
|
accept(element, useHash(element, index));
|
|
@@ -307,7 +315,7 @@ export class Semantic {
|
|
|
307
315
|
}
|
|
308
316
|
skip(n) {
|
|
309
317
|
if (isNumber(n)) {
|
|
310
|
-
return new
|
|
318
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
311
319
|
try {
|
|
312
320
|
let count = 0n;
|
|
313
321
|
let limit = BigInt(n);
|
|
@@ -326,7 +334,7 @@ export class Semantic {
|
|
|
326
334
|
});
|
|
327
335
|
}
|
|
328
336
|
if (isBigInt(n)) {
|
|
329
|
-
return new
|
|
337
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
330
338
|
try {
|
|
331
339
|
let count = 0n;
|
|
332
340
|
this.generator((element, index) => {
|
|
@@ -345,24 +353,27 @@ export class Semantic {
|
|
|
345
353
|
}
|
|
346
354
|
throw new TypeError("Invalid arguments.");
|
|
347
355
|
}
|
|
356
|
+
source() {
|
|
357
|
+
return this.generator;
|
|
358
|
+
}
|
|
348
359
|
sorted(comparator) {
|
|
349
360
|
if (isFunction(comparator)) {
|
|
350
361
|
try {
|
|
351
|
-
return new
|
|
362
|
+
return new SynchronousOrderedCollectable(this.generator, comparator);
|
|
352
363
|
}
|
|
353
364
|
catch (error) {
|
|
354
365
|
throw new Error("Uncaught error on sorted.");
|
|
355
366
|
}
|
|
356
367
|
}
|
|
357
368
|
try {
|
|
358
|
-
return new
|
|
369
|
+
return new SynchronousOrderedCollectable(this.generator, (a, b) => useCompare(a, b));
|
|
359
370
|
}
|
|
360
371
|
catch (error) {
|
|
361
372
|
throw new Error("Uncaught error on sorted.");
|
|
362
373
|
}
|
|
363
374
|
}
|
|
364
375
|
sub(start, end) {
|
|
365
|
-
return new
|
|
376
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
366
377
|
try {
|
|
367
378
|
let count = 0n;
|
|
368
379
|
this.generator((element, index) => {
|
|
@@ -380,7 +391,7 @@ export class Semantic {
|
|
|
380
391
|
});
|
|
381
392
|
}
|
|
382
393
|
takeWhile(predicate) {
|
|
383
|
-
return new
|
|
394
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
384
395
|
try {
|
|
385
396
|
this.generator((element, index) => {
|
|
386
397
|
if (!predicate(element, index)) {
|
|
@@ -395,44 +406,36 @@ export class Semantic {
|
|
|
395
406
|
}
|
|
396
407
|
});
|
|
397
408
|
}
|
|
398
|
-
|
|
409
|
+
toSynchronousCollectable(mapper) {
|
|
399
410
|
if (isFunction(mapper)) {
|
|
400
411
|
try {
|
|
401
|
-
let
|
|
402
|
-
if (
|
|
403
|
-
return
|
|
412
|
+
let synchronousCollectable = mapper(this.generator);
|
|
413
|
+
if (isSynchronousCollectable(synchronousCollectable)) {
|
|
414
|
+
return synchronousCollectable;
|
|
404
415
|
}
|
|
405
416
|
}
|
|
406
417
|
catch (error) {
|
|
407
|
-
throw new Error("Uncaught error on
|
|
418
|
+
throw new Error("Uncaught error on toSynchronousCollectable.");
|
|
408
419
|
}
|
|
409
420
|
}
|
|
410
421
|
try {
|
|
411
|
-
return new
|
|
422
|
+
return new SynchronousUnorderedCollectable(this.generator);
|
|
412
423
|
}
|
|
413
424
|
catch (error) {
|
|
414
|
-
throw new Error("Uncaught error on
|
|
425
|
+
throw new Error("Uncaught error on toSynchronousCollectable.");
|
|
415
426
|
}
|
|
416
427
|
}
|
|
417
428
|
toBigintStatistics() {
|
|
418
429
|
try {
|
|
419
|
-
return new
|
|
430
|
+
return new SynchronousBigIntStatistics(this.generator);
|
|
420
431
|
}
|
|
421
432
|
catch (error) {
|
|
422
433
|
throw new Error("Uncaught error on toBigintStatistics.");
|
|
423
434
|
}
|
|
424
435
|
}
|
|
425
|
-
toEvent() {
|
|
426
|
-
try {
|
|
427
|
-
return new EventCollectable(this.generator);
|
|
428
|
-
}
|
|
429
|
-
catch (error) {
|
|
430
|
-
throw new Error("Uncaught error on toEvent.");
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
436
|
toNumericStatistics() {
|
|
434
437
|
try {
|
|
435
|
-
return new
|
|
438
|
+
return new SynchronousNumericStatistics(this.generator);
|
|
436
439
|
}
|
|
437
440
|
catch (error) {
|
|
438
441
|
throw new Error("Uncaught error on toNumericStatistics.");
|
|
@@ -440,7 +443,7 @@ export class Semantic {
|
|
|
440
443
|
}
|
|
441
444
|
toOrdered() {
|
|
442
445
|
try {
|
|
443
|
-
return new
|
|
446
|
+
return new SynchronousOrderedCollectable(this.generator);
|
|
444
447
|
}
|
|
445
448
|
catch (error) {
|
|
446
449
|
throw new Error("Uncaught error on toOrdered.");
|
|
@@ -448,7 +451,7 @@ export class Semantic {
|
|
|
448
451
|
}
|
|
449
452
|
toUnordered() {
|
|
450
453
|
try {
|
|
451
|
-
return new
|
|
454
|
+
return new SynchronousUnorderedCollectable(this.generator);
|
|
452
455
|
}
|
|
453
456
|
catch (error) {
|
|
454
457
|
throw new Error(String(error));
|
|
@@ -456,7 +459,7 @@ export class Semantic {
|
|
|
456
459
|
}
|
|
457
460
|
toWindow() {
|
|
458
461
|
try {
|
|
459
|
-
return new
|
|
462
|
+
return new SynchronousWindowCollectable(this.generator);
|
|
460
463
|
}
|
|
461
464
|
catch (error) {
|
|
462
465
|
throw new Error("Uncaught error on toWindow.");
|
|
@@ -465,7 +468,7 @@ export class Semantic {
|
|
|
465
468
|
translate(argument1) {
|
|
466
469
|
if (isNumber(argument1)) {
|
|
467
470
|
let offset = argument1;
|
|
468
|
-
return new
|
|
471
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
469
472
|
try {
|
|
470
473
|
this.generator((element, index) => {
|
|
471
474
|
accept(element, index + BigInt(offset));
|
|
@@ -478,7 +481,7 @@ export class Semantic {
|
|
|
478
481
|
}
|
|
479
482
|
else if (isBigInt(argument1)) {
|
|
480
483
|
let offset = argument1;
|
|
481
|
-
return new
|
|
484
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
482
485
|
try {
|
|
483
486
|
this.generator((element, index) => {
|
|
484
487
|
accept(element, index + offset);
|
|
@@ -491,7 +494,7 @@ export class Semantic {
|
|
|
491
494
|
}
|
|
492
495
|
else if (isFunction(argument1)) {
|
|
493
496
|
let translator = argument1;
|
|
494
|
-
return new
|
|
497
|
+
return new SynchronousSemantic((accept, interrupt) => {
|
|
495
498
|
try {
|
|
496
499
|
this.generator((element, index) => {
|
|
497
500
|
accept(element, index + translator(element, index));
|
|
@@ -506,11 +509,11 @@ export class Semantic {
|
|
|
506
509
|
}
|
|
507
510
|
}
|
|
508
511
|
;
|
|
509
|
-
export class
|
|
510
|
-
|
|
512
|
+
export class SynchronousCollectable {
|
|
513
|
+
SynchronousCollectable = SynchronousCollectableSymbol;
|
|
511
514
|
constructor() {
|
|
512
|
-
Object.defineProperty(this, "
|
|
513
|
-
value:
|
|
515
|
+
Object.defineProperty(this, "SynchronousCollectable", {
|
|
516
|
+
value: SynchronousCollectableSymbol,
|
|
514
517
|
enumerable: false,
|
|
515
518
|
writable: false,
|
|
516
519
|
configurable: false
|
|
@@ -519,7 +522,7 @@ export class Collectable {
|
|
|
519
522
|
anyMatch(predicate) {
|
|
520
523
|
if (isFunction(predicate)) {
|
|
521
524
|
try {
|
|
522
|
-
return
|
|
525
|
+
return useSynchronousAnyMatch(predicate).collect(this);
|
|
523
526
|
}
|
|
524
527
|
catch (error) {
|
|
525
528
|
throw new Error("Uncaught error on anyMatch.");
|
|
@@ -528,11 +531,11 @@ export class Collectable {
|
|
|
528
531
|
throw new TypeError("Predicate must be a function.");
|
|
529
532
|
}
|
|
530
533
|
allMatch(predicate) {
|
|
531
|
-
return
|
|
534
|
+
return useSynchronousAllMatch(predicate).collect(this);
|
|
532
535
|
}
|
|
533
536
|
collect(argument1, argument2, argument3, argument4) {
|
|
534
537
|
try {
|
|
535
|
-
if (
|
|
538
|
+
if (isAsynchronousCollector(argument1)) {
|
|
536
539
|
let collector = argument1;
|
|
537
540
|
return collector.collect(this);
|
|
538
541
|
}
|
|
@@ -540,14 +543,14 @@ export class Collectable {
|
|
|
540
543
|
let identity = argument1;
|
|
541
544
|
let accumulator = argument2;
|
|
542
545
|
let finisher = argument3;
|
|
543
|
-
return
|
|
546
|
+
return useSynchronousCollect(identity, accumulator, finisher).collect(this);
|
|
544
547
|
}
|
|
545
548
|
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
546
549
|
let identity = argument1;
|
|
547
550
|
let interrupt = argument2;
|
|
548
551
|
let accumulator = argument3;
|
|
549
552
|
let finisher = argument4;
|
|
550
|
-
return
|
|
553
|
+
return useSynchronousCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
551
554
|
}
|
|
552
555
|
}
|
|
553
556
|
catch (error) {
|
|
@@ -556,12 +559,12 @@ export class Collectable {
|
|
|
556
559
|
throw new TypeError("Invalid arguments.");
|
|
557
560
|
}
|
|
558
561
|
count() {
|
|
559
|
-
return
|
|
562
|
+
return useSynchronousCount().collect(this.source());
|
|
560
563
|
}
|
|
561
564
|
error(argument1, argument2, argument3) {
|
|
562
565
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
563
566
|
try {
|
|
564
|
-
|
|
567
|
+
useSynchronousError().collect(this.source());
|
|
565
568
|
}
|
|
566
569
|
catch (error) {
|
|
567
570
|
throw new Error("Uncaught error on error.");
|
|
@@ -570,7 +573,7 @@ export class Collectable {
|
|
|
570
573
|
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
571
574
|
try {
|
|
572
575
|
let accumulator = argument1;
|
|
573
|
-
|
|
576
|
+
useSynchronousError(accumulator).collect(this.source());
|
|
574
577
|
}
|
|
575
578
|
catch (error) {
|
|
576
579
|
throw new Error("Uncaught error on error.");
|
|
@@ -581,7 +584,7 @@ export class Collectable {
|
|
|
581
584
|
let prefix = argument1;
|
|
582
585
|
let accumulator = argument2;
|
|
583
586
|
let suffix = argument3;
|
|
584
|
-
|
|
587
|
+
useSynchronousError(prefix, accumulator, suffix).collect(this.source());
|
|
585
588
|
}
|
|
586
589
|
catch (error) {
|
|
587
590
|
throw new Error("Uncaught error on error.");
|
|
@@ -596,7 +599,7 @@ export class Collectable {
|
|
|
596
599
|
}
|
|
597
600
|
findAny() {
|
|
598
601
|
try {
|
|
599
|
-
return
|
|
602
|
+
return useSynchronousFindAny().collect(this.source());
|
|
600
603
|
}
|
|
601
604
|
catch (error) {
|
|
602
605
|
throw new Error("Uncaught error on findAny.");
|
|
@@ -605,7 +608,7 @@ export class Collectable {
|
|
|
605
608
|
findAt(index) {
|
|
606
609
|
if (isBigInt(index)) {
|
|
607
610
|
try {
|
|
608
|
-
return
|
|
611
|
+
return useSynchronousFindAt(index).collect(this.source());
|
|
609
612
|
}
|
|
610
613
|
catch (error) {
|
|
611
614
|
throw new Error("Uncaught error on findAt.");
|
|
@@ -613,7 +616,7 @@ export class Collectable {
|
|
|
613
616
|
}
|
|
614
617
|
else if (isNumber(index)) {
|
|
615
618
|
try {
|
|
616
|
-
return
|
|
619
|
+
return useSynchronousFindAt(index).collect(this.source());
|
|
617
620
|
}
|
|
618
621
|
catch (error) {
|
|
619
622
|
throw new Error("Uncaught error on findAt.");
|
|
@@ -623,7 +626,7 @@ export class Collectable {
|
|
|
623
626
|
}
|
|
624
627
|
findFirst() {
|
|
625
628
|
try {
|
|
626
|
-
return
|
|
629
|
+
return useSynchronousFindFirst().collect(this.source());
|
|
627
630
|
}
|
|
628
631
|
catch (error) {
|
|
629
632
|
throw new Error("Uncaught error on findFirst.");
|
|
@@ -631,7 +634,7 @@ export class Collectable {
|
|
|
631
634
|
}
|
|
632
635
|
findLast() {
|
|
633
636
|
try {
|
|
634
|
-
return
|
|
637
|
+
return useSynchronousFindLast().collect(this.source());
|
|
635
638
|
}
|
|
636
639
|
catch (error) {
|
|
637
640
|
throw new Error("Uncaught error on findLast.");
|
|
@@ -640,7 +643,7 @@ export class Collectable {
|
|
|
640
643
|
findMaximum(argument1) {
|
|
641
644
|
try {
|
|
642
645
|
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
643
|
-
return
|
|
646
|
+
return useSynchronousFindMaximum(comparator).collect(this.source());
|
|
644
647
|
}
|
|
645
648
|
catch (error) {
|
|
646
649
|
throw new Error("Uncaught error on findMaximum.");
|
|
@@ -649,7 +652,7 @@ export class Collectable {
|
|
|
649
652
|
findMinimum(argument1) {
|
|
650
653
|
try {
|
|
651
654
|
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
652
|
-
return
|
|
655
|
+
return useSynchronousFindMinimum(comparator).collect(this.source());
|
|
653
656
|
}
|
|
654
657
|
catch (error) {
|
|
655
658
|
throw new Error("Uncaught error on findMinimum.");
|
|
@@ -658,7 +661,7 @@ export class Collectable {
|
|
|
658
661
|
forEach(action) {
|
|
659
662
|
if (isFunction(action)) {
|
|
660
663
|
try {
|
|
661
|
-
|
|
664
|
+
useSynchronousForEach(action).collect(this);
|
|
662
665
|
}
|
|
663
666
|
catch (error) {
|
|
664
667
|
throw new Error("Uncaught error on forEach.");
|
|
@@ -671,7 +674,7 @@ export class Collectable {
|
|
|
671
674
|
group(classifier) {
|
|
672
675
|
if (isFunction(classifier)) {
|
|
673
676
|
try {
|
|
674
|
-
return
|
|
677
|
+
return useSynchronousGroup(classifier).collect(this.source());
|
|
675
678
|
}
|
|
676
679
|
catch (error) {
|
|
677
680
|
throw new Error("Uncaught error on group.");
|
|
@@ -682,7 +685,7 @@ export class Collectable {
|
|
|
682
685
|
groupBy(keyExtractor, valueExtractor) {
|
|
683
686
|
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
684
687
|
try {
|
|
685
|
-
return
|
|
688
|
+
return useSynchronousGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
686
689
|
}
|
|
687
690
|
catch (error) {
|
|
688
691
|
throw new Error("Uncaught error on groupBy.");
|
|
@@ -693,7 +696,7 @@ export class Collectable {
|
|
|
693
696
|
join(argument1, argument2, argument3) {
|
|
694
697
|
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
695
698
|
try {
|
|
696
|
-
return
|
|
699
|
+
return useSynchronousJoin().collect(this.source());
|
|
697
700
|
}
|
|
698
701
|
catch (error) {
|
|
699
702
|
throw new Error("Uncaught error on join.");
|
|
@@ -702,7 +705,7 @@ export class Collectable {
|
|
|
702
705
|
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
703
706
|
try {
|
|
704
707
|
let delimiter = argument1;
|
|
705
|
-
return
|
|
708
|
+
return useSynchronousJoin(delimiter).collect(this.source());
|
|
706
709
|
}
|
|
707
710
|
catch (error) {
|
|
708
711
|
throw new Error("Uncaught error on join.");
|
|
@@ -713,7 +716,7 @@ export class Collectable {
|
|
|
713
716
|
let prefix = argument1;
|
|
714
717
|
let accumulator = argument2;
|
|
715
718
|
let suffix = argument3;
|
|
716
|
-
return
|
|
719
|
+
return useSynchronousJoin(prefix, accumulator, suffix).collect(this.source());
|
|
717
720
|
}
|
|
718
721
|
catch (error) {
|
|
719
722
|
throw new Error("Uncaught error on join.");
|
|
@@ -724,7 +727,7 @@ export class Collectable {
|
|
|
724
727
|
let prefix = argument1;
|
|
725
728
|
let delimiter = argument2;
|
|
726
729
|
let suffix = argument3;
|
|
727
|
-
return
|
|
730
|
+
return useSynchronousJoin(prefix, delimiter, suffix).collect(this.source());
|
|
728
731
|
}
|
|
729
732
|
catch (error) {
|
|
730
733
|
throw new Error("Uncaught error on join.");
|
|
@@ -736,7 +739,7 @@ export class Collectable {
|
|
|
736
739
|
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
737
740
|
try {
|
|
738
741
|
let accumulator = argument1;
|
|
739
|
-
|
|
742
|
+
useSynchronousLog(accumulator).collect(this.source());
|
|
740
743
|
}
|
|
741
744
|
catch (error) {
|
|
742
745
|
throw new Error("Uncaught error on log.");
|
|
@@ -747,7 +750,7 @@ export class Collectable {
|
|
|
747
750
|
let prefix = argument1;
|
|
748
751
|
let accumulator = argument2;
|
|
749
752
|
let suffix = argument3;
|
|
750
|
-
|
|
753
|
+
useSynchronousLog(prefix, accumulator, suffix).collect(this.source());
|
|
751
754
|
}
|
|
752
755
|
catch (error) {
|
|
753
756
|
throw new Error("Uncaught error on log.");
|
|
@@ -755,7 +758,7 @@ export class Collectable {
|
|
|
755
758
|
}
|
|
756
759
|
else {
|
|
757
760
|
try {
|
|
758
|
-
|
|
761
|
+
useSynchronousLog().collect(this.source());
|
|
759
762
|
}
|
|
760
763
|
catch (error) {
|
|
761
764
|
throw new Error("Uncaught error on log.");
|
|
@@ -765,7 +768,7 @@ export class Collectable {
|
|
|
765
768
|
nonMatch(predicate) {
|
|
766
769
|
if (isFunction(predicate)) {
|
|
767
770
|
try {
|
|
768
|
-
return
|
|
771
|
+
return useSynchronousNoneMatch(predicate).collect(this.source());
|
|
769
772
|
}
|
|
770
773
|
catch (error) {
|
|
771
774
|
throw new Error("Uncaught error on nonMatch.");
|
|
@@ -776,7 +779,7 @@ export class Collectable {
|
|
|
776
779
|
partition(count) {
|
|
777
780
|
if (isBigInt(count)) {
|
|
778
781
|
try {
|
|
779
|
-
return
|
|
782
|
+
return useSynchronousPartition(count).collect(this.source());
|
|
780
783
|
}
|
|
781
784
|
catch (error) {
|
|
782
785
|
throw new Error("Uncaught error on partition.");
|
|
@@ -787,7 +790,7 @@ export class Collectable {
|
|
|
787
790
|
partitionBy(classifier) {
|
|
788
791
|
if (isFunction(classifier)) {
|
|
789
792
|
try {
|
|
790
|
-
let collector =
|
|
793
|
+
let collector = useSynchronousPartitionBy(classifier);
|
|
791
794
|
return collector.collect(this.source());
|
|
792
795
|
}
|
|
793
796
|
catch (error) {
|
|
@@ -800,7 +803,7 @@ export class Collectable {
|
|
|
800
803
|
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
801
804
|
try {
|
|
802
805
|
let accumulator = argument1;
|
|
803
|
-
return
|
|
806
|
+
return useSynchronousReduce(accumulator).collect(this.source());
|
|
804
807
|
}
|
|
805
808
|
catch (error) {
|
|
806
809
|
throw new Error("Uncaught error on reduce.");
|
|
@@ -810,7 +813,7 @@ export class Collectable {
|
|
|
810
813
|
try {
|
|
811
814
|
let identity = argument1;
|
|
812
815
|
let accumulator = argument2;
|
|
813
|
-
return
|
|
816
|
+
return useSynchronousReduce(identity, accumulator).collect(this.source());
|
|
814
817
|
}
|
|
815
818
|
catch (error) {
|
|
816
819
|
throw new Error("Uncaught error on reduce.");
|
|
@@ -821,7 +824,7 @@ export class Collectable {
|
|
|
821
824
|
let identity = argument1;
|
|
822
825
|
let accumulator = argument2;
|
|
823
826
|
let finisher = argument3;
|
|
824
|
-
return
|
|
827
|
+
return useSynchronousReduce(identity, accumulator, finisher).collect(this.source());
|
|
825
828
|
}
|
|
826
829
|
catch (error) {
|
|
827
830
|
throw new Error("Uncaught error on reduce.");
|
|
@@ -835,7 +838,7 @@ export class Collectable {
|
|
|
835
838
|
let source = this.source();
|
|
836
839
|
if (isFunction(source)) {
|
|
837
840
|
try {
|
|
838
|
-
return new
|
|
841
|
+
return new SynchronousSemantic(source);
|
|
839
842
|
}
|
|
840
843
|
catch (error) {
|
|
841
844
|
throw new Error("Uncaught error on semantic.");
|
|
@@ -847,7 +850,7 @@ export class Collectable {
|
|
|
847
850
|
}
|
|
848
851
|
toArray() {
|
|
849
852
|
try {
|
|
850
|
-
return
|
|
853
|
+
return useSynchronousToArray().collect(this.source());
|
|
851
854
|
}
|
|
852
855
|
catch (error) {
|
|
853
856
|
throw new Error("Uncaught error on toArray.");
|
|
@@ -855,7 +858,7 @@ export class Collectable {
|
|
|
855
858
|
}
|
|
856
859
|
toMap(keyExtractor, valueExtractor = (element) => element) {
|
|
857
860
|
try {
|
|
858
|
-
return
|
|
861
|
+
return useSynchronousToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
859
862
|
}
|
|
860
863
|
catch (error) {
|
|
861
864
|
throw new Error("Uncaught error on toMap.");
|
|
@@ -863,7 +866,7 @@ export class Collectable {
|
|
|
863
866
|
}
|
|
864
867
|
toSet() {
|
|
865
868
|
try {
|
|
866
|
-
return
|
|
869
|
+
return useSynchronousToSet().collect(this.source());
|
|
867
870
|
}
|
|
868
871
|
catch (error) {
|
|
869
872
|
throw new Error("Uncaught error on toSet.");
|
|
@@ -875,10 +878,10 @@ export class Collectable {
|
|
|
875
878
|
let stream = argument1;
|
|
876
879
|
if (isFunction(argument2)) {
|
|
877
880
|
let accumulator = argument2;
|
|
878
|
-
return
|
|
881
|
+
return useSynchronousWrite(stream, accumulator).collect(this.source());
|
|
879
882
|
}
|
|
880
883
|
else {
|
|
881
|
-
return
|
|
884
|
+
return useSynchronousWrite(stream).collect(this.source());
|
|
882
885
|
}
|
|
883
886
|
}
|
|
884
887
|
catch (error) {
|
|
@@ -889,111 +892,15 @@ export class Collectable {
|
|
|
889
892
|
}
|
|
890
893
|
}
|
|
891
894
|
;
|
|
892
|
-
export class
|
|
893
|
-
|
|
894
|
-
generator;
|
|
895
|
-
constructor(argument1) {
|
|
896
|
-
super();
|
|
897
|
-
if (isFunction(argument1)) {
|
|
898
|
-
let generator = argument1;
|
|
899
|
-
this.generator = generator;
|
|
900
|
-
Object.defineProperty(this, "AsyncCollectable", {
|
|
901
|
-
value: AsyncCollectableSymbol,
|
|
902
|
-
writable: false,
|
|
903
|
-
enumerable: false,
|
|
904
|
-
configurable: false
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
else {
|
|
908
|
-
throw new TypeError("Source must be an iterable or a generator function.");
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
source() {
|
|
912
|
-
return this.generator;
|
|
913
|
-
}
|
|
914
|
-
*[Symbol.iterator]() {
|
|
915
|
-
try {
|
|
916
|
-
let collector = useToArray();
|
|
917
|
-
yield* collector.collect(this.generator);
|
|
918
|
-
}
|
|
919
|
-
catch (error) {
|
|
920
|
-
throw new Error("Uncaught error on Generator.");
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
async *[Symbol.asyncIterator]() {
|
|
924
|
-
try {
|
|
925
|
-
let collector = useToArray();
|
|
926
|
-
yield* collector.collect(this.generator);
|
|
927
|
-
}
|
|
928
|
-
catch (error) {
|
|
929
|
-
throw new Error("Uncaught error on Generator.");
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
export class UnorderedCollectable extends Collectable {
|
|
934
|
-
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
935
|
-
buffer = new Map();
|
|
936
|
-
constructor(argument1) {
|
|
937
|
-
super();
|
|
938
|
-
if (isFunction(argument1)) {
|
|
939
|
-
let generator = argument1;
|
|
940
|
-
generator((element, index) => {
|
|
941
|
-
this.buffer.set(index, element);
|
|
942
|
-
}, () => false);
|
|
943
|
-
Object.defineProperties(this, {
|
|
944
|
-
"UnorderedCollectable": {
|
|
945
|
-
value: UnorderedCollectableSymbol,
|
|
946
|
-
writable: false,
|
|
947
|
-
enumerable: false,
|
|
948
|
-
configurable: false
|
|
949
|
-
}
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
else {
|
|
953
|
-
throw new TypeError("Source must be an iterable or a generator function.");
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
source() {
|
|
957
|
-
return (accept, interrupt) => {
|
|
958
|
-
for (let [index, element] of this.buffer) {
|
|
959
|
-
if (interrupt(element, index)) {
|
|
960
|
-
break;
|
|
961
|
-
}
|
|
962
|
-
accept(element, index);
|
|
963
|
-
}
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
*[Symbol.iterator]() {
|
|
967
|
-
try {
|
|
968
|
-
for (let [_index, element] of this.buffer) {
|
|
969
|
-
yield element;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
catch (error) {
|
|
973
|
-
throw new Error("Uncaught error on Generator.");
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
async *[Symbol.asyncIterator]() {
|
|
977
|
-
try {
|
|
978
|
-
for (let [_index, element] of this.buffer) {
|
|
979
|
-
yield element;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
catch (error) {
|
|
983
|
-
throw new Error("Uncaught error on AsyncGenerator.");
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
;
|
|
988
|
-
export class OrderedCollectable extends Collectable {
|
|
989
|
-
OrderedCollectable = OrderedCollectableSymbol;
|
|
895
|
+
export class SynchronousOrderedCollectable extends SynchronousCollectable {
|
|
896
|
+
SynchronousOrderedCollectable = SynchronousOrderedCollectableSymbol;
|
|
990
897
|
buffer;
|
|
991
898
|
constructor(argument1, argument2) {
|
|
992
899
|
super();
|
|
993
900
|
if (isFunction(argument1)) {
|
|
994
901
|
try {
|
|
995
902
|
if (isFunction(argument2)) {
|
|
996
|
-
let collector =
|
|
903
|
+
let collector = useSynchronousToArray();
|
|
997
904
|
this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
|
|
998
905
|
return {
|
|
999
906
|
element: element,
|
|
@@ -1002,7 +909,7 @@ export class OrderedCollectable extends Collectable {
|
|
|
1002
909
|
});
|
|
1003
910
|
}
|
|
1004
911
|
else {
|
|
1005
|
-
let collector =
|
|
912
|
+
let collector = useSynchronousToArray();
|
|
1006
913
|
this.buffer = collector.collect(argument1).map((element, index) => {
|
|
1007
914
|
return {
|
|
1008
915
|
element: element,
|
|
@@ -1013,8 +920,8 @@ export class OrderedCollectable extends Collectable {
|
|
|
1013
920
|
});
|
|
1014
921
|
}
|
|
1015
922
|
Object.defineProperties(this, {
|
|
1016
|
-
"
|
|
1017
|
-
value:
|
|
923
|
+
"SynchronousOrderedCollectable": {
|
|
924
|
+
value: SynchronousOrderedCollectableSymbol,
|
|
1018
925
|
writable: false,
|
|
1019
926
|
enumerable: false,
|
|
1020
927
|
configurable: false
|
|
@@ -1075,13 +982,68 @@ export class OrderedCollectable extends Collectable {
|
|
|
1075
982
|
}
|
|
1076
983
|
}
|
|
1077
984
|
;
|
|
1078
|
-
export class
|
|
1079
|
-
|
|
985
|
+
export class SynchronousUnorderedCollectable extends SynchronousCollectable {
|
|
986
|
+
SynchronousUnorderedCollectable = SynchronousUnorderedCollectableSymbol;
|
|
987
|
+
buffer = new Map();
|
|
988
|
+
constructor(argument1) {
|
|
989
|
+
super();
|
|
990
|
+
if (isFunction(argument1)) {
|
|
991
|
+
let generator = argument1;
|
|
992
|
+
generator((element, index) => {
|
|
993
|
+
this.buffer.set(index, element);
|
|
994
|
+
}, () => false);
|
|
995
|
+
Object.defineProperties(this, {
|
|
996
|
+
"SynchronousUnorderedCollectable": {
|
|
997
|
+
value: SynchronousUnorderedCollectableSymbol,
|
|
998
|
+
writable: false,
|
|
999
|
+
enumerable: false,
|
|
1000
|
+
configurable: false
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
source() {
|
|
1009
|
+
return (accept, interrupt) => {
|
|
1010
|
+
for (let [index, element] of this.buffer) {
|
|
1011
|
+
if (interrupt(element, index)) {
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
accept(element, index);
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
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
|
+
}
|
|
1039
|
+
;
|
|
1040
|
+
export class SynchronousStatistics extends SynchronousOrderedCollectable {
|
|
1041
|
+
SynchronousStatistics = SynchronousStatisticsSymbol;
|
|
1080
1042
|
constructor(parameter, comparator) {
|
|
1081
|
-
super(parameter, comparator
|
|
1043
|
+
super(parameter, validate(comparator) ? comparator : useCompare);
|
|
1082
1044
|
Object.defineProperties(this, {
|
|
1083
|
-
"
|
|
1084
|
-
value:
|
|
1045
|
+
"SynchronousStatistics": {
|
|
1046
|
+
value: SynchronousStatisticsSymbol,
|
|
1085
1047
|
enumerable: false,
|
|
1086
1048
|
writable: false,
|
|
1087
1049
|
configurable: false
|
|
@@ -1112,17 +1074,17 @@ export class Statistics extends OrderedCollectable {
|
|
|
1112
1074
|
return BigInt(this.buffer.length);
|
|
1113
1075
|
}
|
|
1114
1076
|
frequency() {
|
|
1115
|
-
return
|
|
1077
|
+
return useSynchronousFrequency().collect(this.source());
|
|
1116
1078
|
}
|
|
1117
1079
|
}
|
|
1118
1080
|
;
|
|
1119
|
-
export class
|
|
1120
|
-
|
|
1081
|
+
export class SynchronousBigIntStatistics extends SynchronousStatistics {
|
|
1082
|
+
BigIntStatistics = SynchronousBigIntStatisticsSymbol;
|
|
1121
1083
|
constructor(parameter, comparator) {
|
|
1122
1084
|
super(parameter, comparator || useCompare);
|
|
1123
1085
|
Object.defineProperties(this, {
|
|
1124
|
-
"
|
|
1125
|
-
value:
|
|
1086
|
+
"SynchronousBigIntStatistics": {
|
|
1087
|
+
value: SynchronousBigIntStatisticsSymbol,
|
|
1126
1088
|
enumerable: false,
|
|
1127
1089
|
writable: false,
|
|
1128
1090
|
configurable: false
|
|
@@ -1149,15 +1111,13 @@ export class NumericStatistics extends Statistics {
|
|
|
1149
1111
|
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1150
1112
|
}
|
|
1151
1113
|
}
|
|
1152
|
-
average(
|
|
1114
|
+
average(argument1) {
|
|
1153
1115
|
if (this.isEmpty()) {
|
|
1154
|
-
return
|
|
1116
|
+
return 0n;
|
|
1155
1117
|
}
|
|
1156
1118
|
try {
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
return useNumericAverage().collect(this.source());
|
|
1119
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1120
|
+
return useSynchronousBigIntAverage(mapper).collect(this.source());
|
|
1161
1121
|
}
|
|
1162
1122
|
catch (error) {
|
|
1163
1123
|
throw new Error("Uncaught error on average.");
|
|
@@ -1165,13 +1125,10 @@ export class NumericStatistics extends Statistics {
|
|
|
1165
1125
|
}
|
|
1166
1126
|
range(argument1) {
|
|
1167
1127
|
if (this.isEmpty()) {
|
|
1168
|
-
return
|
|
1128
|
+
return 0n;
|
|
1169
1129
|
}
|
|
1170
1130
|
try {
|
|
1171
|
-
|
|
1172
|
-
return 0;
|
|
1173
|
-
}
|
|
1174
|
-
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1131
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1175
1132
|
let count = this.buffer.length;
|
|
1176
1133
|
let minimum = this.buffer[0].element;
|
|
1177
1134
|
let maximum = this.buffer[count - 1].element;
|
|
@@ -1183,11 +1140,11 @@ export class NumericStatistics extends Statistics {
|
|
|
1183
1140
|
}
|
|
1184
1141
|
variance(argument1) {
|
|
1185
1142
|
if (this.isEmpty() || this.count() === 1n) {
|
|
1186
|
-
return
|
|
1143
|
+
return 0n;
|
|
1187
1144
|
}
|
|
1188
1145
|
try {
|
|
1189
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1190
|
-
return
|
|
1146
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1147
|
+
return useSynchronousBigIntVariance(mapper).collect(this.source());
|
|
1191
1148
|
}
|
|
1192
1149
|
catch (error) {
|
|
1193
1150
|
throw new Error("Uncaught error on variance.");
|
|
@@ -1195,8 +1152,9 @@ export class NumericStatistics extends Statistics {
|
|
|
1195
1152
|
}
|
|
1196
1153
|
standardDeviation(argument1) {
|
|
1197
1154
|
try {
|
|
1198
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1199
|
-
|
|
1155
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1156
|
+
let variance = this.variance(mapper);
|
|
1157
|
+
return BigInt(Math.sqrt(Number(variance)));
|
|
1200
1158
|
}
|
|
1201
1159
|
catch (error) {
|
|
1202
1160
|
throw new Error("Uncaught error on standardDeviation.");
|
|
@@ -1204,11 +1162,11 @@ export class NumericStatistics extends Statistics {
|
|
|
1204
1162
|
}
|
|
1205
1163
|
mean(argument1) {
|
|
1206
1164
|
if (this.isEmpty()) {
|
|
1207
|
-
return
|
|
1165
|
+
return 0n;
|
|
1208
1166
|
}
|
|
1209
1167
|
try {
|
|
1210
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1211
|
-
return
|
|
1168
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1169
|
+
return useSynchronousBigIntAverage(mapper).collect(this.source());
|
|
1212
1170
|
}
|
|
1213
1171
|
catch (error) {
|
|
1214
1172
|
throw new Error("Uncaught error on mean.");
|
|
@@ -1216,11 +1174,11 @@ export class NumericStatistics extends Statistics {
|
|
|
1216
1174
|
}
|
|
1217
1175
|
median(argument1) {
|
|
1218
1176
|
if (this.isEmpty()) {
|
|
1219
|
-
return
|
|
1177
|
+
return 0n;
|
|
1220
1178
|
}
|
|
1221
1179
|
try {
|
|
1222
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1223
|
-
return
|
|
1180
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1181
|
+
return useSynchronousBigIntMedian(mapper).collect(this.source());
|
|
1224
1182
|
}
|
|
1225
1183
|
catch (error) {
|
|
1226
1184
|
throw new Error("Uncaught error on median.");
|
|
@@ -1228,11 +1186,11 @@ export class NumericStatistics extends Statistics {
|
|
|
1228
1186
|
}
|
|
1229
1187
|
mode(argument1) {
|
|
1230
1188
|
if (this.isEmpty()) {
|
|
1231
|
-
return
|
|
1189
|
+
return 0n;
|
|
1232
1190
|
}
|
|
1233
1191
|
try {
|
|
1234
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1235
|
-
return
|
|
1192
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1193
|
+
return useSynchronousBigIntMode(mapper).collect(this.source());
|
|
1236
1194
|
}
|
|
1237
1195
|
catch (error) {
|
|
1238
1196
|
throw new Error("Uncaught error on mode.");
|
|
@@ -1240,11 +1198,11 @@ export class NumericStatistics extends Statistics {
|
|
|
1240
1198
|
}
|
|
1241
1199
|
summate(argument1) {
|
|
1242
1200
|
if (this.isEmpty()) {
|
|
1243
|
-
return
|
|
1201
|
+
return 0n;
|
|
1244
1202
|
}
|
|
1245
1203
|
try {
|
|
1246
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1247
|
-
return
|
|
1204
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1205
|
+
return useSynchronousBigIntSummate(mapper).collect(this.source());
|
|
1248
1206
|
}
|
|
1249
1207
|
catch (error) {
|
|
1250
1208
|
throw new Error("Uncaught error on summate.");
|
|
@@ -1252,13 +1210,13 @@ export class NumericStatistics extends Statistics {
|
|
|
1252
1210
|
}
|
|
1253
1211
|
quantile(quantile, argument1) {
|
|
1254
1212
|
if (this.isEmpty()) {
|
|
1255
|
-
return
|
|
1213
|
+
return 0n;
|
|
1256
1214
|
}
|
|
1257
|
-
if (quantile < 0 || quantile > 1) {
|
|
1215
|
+
if (typeof quantile !== "number" || quantile < 0 || quantile > 1) {
|
|
1258
1216
|
throw new RangeError("Invalid quantile.");
|
|
1259
1217
|
}
|
|
1260
1218
|
try {
|
|
1261
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1219
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1262
1220
|
let count = Number(this.count());
|
|
1263
1221
|
let index = Math.floor(quantile * count);
|
|
1264
1222
|
if (index === count) {
|
|
@@ -1273,10 +1231,10 @@ export class NumericStatistics extends Statistics {
|
|
|
1273
1231
|
}
|
|
1274
1232
|
interquartileRange(argument1) {
|
|
1275
1233
|
if (this.isEmpty()) {
|
|
1276
|
-
return
|
|
1234
|
+
return 0n;
|
|
1277
1235
|
}
|
|
1278
1236
|
try {
|
|
1279
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1237
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1280
1238
|
let lower = this.quantile(0.25, mapper);
|
|
1281
1239
|
let upper = this.quantile(0.75, mapper);
|
|
1282
1240
|
return upper - lower;
|
|
@@ -1287,22 +1245,22 @@ export class NumericStatistics extends Statistics {
|
|
|
1287
1245
|
}
|
|
1288
1246
|
skewness(argument1) {
|
|
1289
1247
|
if (this.isEmpty()) {
|
|
1290
|
-
return
|
|
1248
|
+
return 0n;
|
|
1291
1249
|
}
|
|
1292
1250
|
try {
|
|
1293
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1251
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1294
1252
|
let mean = this.mean(mapper);
|
|
1295
1253
|
let standardDeviation = this.standardDeviation(mapper);
|
|
1296
|
-
if (standardDeviation ===
|
|
1297
|
-
return
|
|
1254
|
+
if (standardDeviation === 0n) {
|
|
1255
|
+
return 0n;
|
|
1298
1256
|
}
|
|
1299
1257
|
let data = this.toArray().map(item => mapper(item));
|
|
1300
|
-
let summate =
|
|
1258
|
+
let summate = 0n;
|
|
1301
1259
|
for (let value of data) {
|
|
1302
|
-
let z =
|
|
1303
|
-
summate +=
|
|
1260
|
+
let z = value - mean;
|
|
1261
|
+
summate += z * z * z;
|
|
1304
1262
|
}
|
|
1305
|
-
return summate / data.length;
|
|
1263
|
+
return summate / BigInt(data.length);
|
|
1306
1264
|
}
|
|
1307
1265
|
catch (error) {
|
|
1308
1266
|
throw new Error("Uncaught error on skewness.");
|
|
@@ -1310,22 +1268,23 @@ export class NumericStatistics extends Statistics {
|
|
|
1310
1268
|
}
|
|
1311
1269
|
kurtosis(argument1) {
|
|
1312
1270
|
if (this.isEmpty()) {
|
|
1313
|
-
return
|
|
1271
|
+
return 0n;
|
|
1314
1272
|
}
|
|
1315
1273
|
try {
|
|
1316
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1274
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1317
1275
|
let mean = this.mean(mapper);
|
|
1318
1276
|
let standardDeviation = this.standardDeviation(mapper);
|
|
1319
|
-
if (standardDeviation ===
|
|
1320
|
-
return
|
|
1277
|
+
if (standardDeviation === 0n) {
|
|
1278
|
+
return 0n;
|
|
1321
1279
|
}
|
|
1322
1280
|
let data = this.toArray().map(item => mapper(item));
|
|
1323
|
-
let summate =
|
|
1281
|
+
let summate = 0n;
|
|
1282
|
+
let count = data.length;
|
|
1324
1283
|
for (let value of data) {
|
|
1325
|
-
let z =
|
|
1326
|
-
summate +=
|
|
1284
|
+
let z = value - mean;
|
|
1285
|
+
summate += z * z * z * z;
|
|
1327
1286
|
}
|
|
1328
|
-
return summate / (
|
|
1287
|
+
return summate / BigInt(count * count) - 3n;
|
|
1329
1288
|
}
|
|
1330
1289
|
catch (error) {
|
|
1331
1290
|
throw new Error("Uncaught error on kurtosis.");
|
|
@@ -1333,13 +1292,13 @@ export class NumericStatistics extends Statistics {
|
|
|
1333
1292
|
}
|
|
1334
1293
|
}
|
|
1335
1294
|
;
|
|
1336
|
-
export class
|
|
1337
|
-
|
|
1295
|
+
export class SynchronousNumericStatistics extends SynchronousStatistics {
|
|
1296
|
+
SynchronousNumericStatistics = SynchronousNumericStatisticsSymbol;
|
|
1338
1297
|
constructor(parameter, comparator) {
|
|
1339
1298
|
super(parameter, comparator || useCompare);
|
|
1340
1299
|
Object.defineProperties(this, {
|
|
1341
|
-
"
|
|
1342
|
-
value:
|
|
1300
|
+
"SynchronousNumericStatistics": {
|
|
1301
|
+
value: SynchronousNumericStatisticsSymbol,
|
|
1343
1302
|
enumerable: false,
|
|
1344
1303
|
writable: false,
|
|
1345
1304
|
configurable: false
|
|
@@ -1366,13 +1325,15 @@ export class BigIntStatistics extends Statistics {
|
|
|
1366
1325
|
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1367
1326
|
}
|
|
1368
1327
|
}
|
|
1369
|
-
average(
|
|
1328
|
+
average(mapper) {
|
|
1370
1329
|
if (this.isEmpty()) {
|
|
1371
|
-
return
|
|
1330
|
+
return 0;
|
|
1372
1331
|
}
|
|
1373
1332
|
try {
|
|
1374
|
-
|
|
1375
|
-
|
|
1333
|
+
if (isFunction(mapper)) {
|
|
1334
|
+
return useSynchronousNumericAverage(mapper).collect(this.source());
|
|
1335
|
+
}
|
|
1336
|
+
return useSynchronousNumericAverage().collect(this.source());
|
|
1376
1337
|
}
|
|
1377
1338
|
catch (error) {
|
|
1378
1339
|
throw new Error("Uncaught error on average.");
|
|
@@ -1380,10 +1341,13 @@ export class BigIntStatistics extends Statistics {
|
|
|
1380
1341
|
}
|
|
1381
1342
|
range(argument1) {
|
|
1382
1343
|
if (this.isEmpty()) {
|
|
1383
|
-
return
|
|
1344
|
+
return 0;
|
|
1384
1345
|
}
|
|
1385
1346
|
try {
|
|
1386
|
-
|
|
1347
|
+
if (this.count() === 1n) {
|
|
1348
|
+
return 0;
|
|
1349
|
+
}
|
|
1350
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1387
1351
|
let count = this.buffer.length;
|
|
1388
1352
|
let minimum = this.buffer[0].element;
|
|
1389
1353
|
let maximum = this.buffer[count - 1].element;
|
|
@@ -1395,11 +1359,11 @@ export class BigIntStatistics extends Statistics {
|
|
|
1395
1359
|
}
|
|
1396
1360
|
variance(argument1) {
|
|
1397
1361
|
if (this.isEmpty() || this.count() === 1n) {
|
|
1398
|
-
return
|
|
1362
|
+
return 0;
|
|
1399
1363
|
}
|
|
1400
1364
|
try {
|
|
1401
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1402
|
-
return
|
|
1365
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1366
|
+
return useSynchronousNumericVariance(mapper).collect(this.source());
|
|
1403
1367
|
}
|
|
1404
1368
|
catch (error) {
|
|
1405
1369
|
throw new Error("Uncaught error on variance.");
|
|
@@ -1407,9 +1371,8 @@ export class BigIntStatistics extends Statistics {
|
|
|
1407
1371
|
}
|
|
1408
1372
|
standardDeviation(argument1) {
|
|
1409
1373
|
try {
|
|
1410
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1411
|
-
|
|
1412
|
-
return BigInt(Math.sqrt(Number(variance)));
|
|
1374
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1375
|
+
return useSynchronousNumericStandardDeviation(mapper).collect(this.source());
|
|
1413
1376
|
}
|
|
1414
1377
|
catch (error) {
|
|
1415
1378
|
throw new Error("Uncaught error on standardDeviation.");
|
|
@@ -1417,11 +1380,11 @@ export class BigIntStatistics extends Statistics {
|
|
|
1417
1380
|
}
|
|
1418
1381
|
mean(argument1) {
|
|
1419
1382
|
if (this.isEmpty()) {
|
|
1420
|
-
return
|
|
1383
|
+
return 0;
|
|
1421
1384
|
}
|
|
1422
1385
|
try {
|
|
1423
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1424
|
-
return
|
|
1386
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1387
|
+
return useSynchronousNumericAverage(mapper).collect(this.source());
|
|
1425
1388
|
}
|
|
1426
1389
|
catch (error) {
|
|
1427
1390
|
throw new Error("Uncaught error on mean.");
|
|
@@ -1429,11 +1392,11 @@ export class BigIntStatistics extends Statistics {
|
|
|
1429
1392
|
}
|
|
1430
1393
|
median(argument1) {
|
|
1431
1394
|
if (this.isEmpty()) {
|
|
1432
|
-
return
|
|
1395
|
+
return 0;
|
|
1433
1396
|
}
|
|
1434
1397
|
try {
|
|
1435
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1436
|
-
return
|
|
1398
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1399
|
+
return useSynchronousNumericMedian(mapper).collect(this.source());
|
|
1437
1400
|
}
|
|
1438
1401
|
catch (error) {
|
|
1439
1402
|
throw new Error("Uncaught error on median.");
|
|
@@ -1441,11 +1404,11 @@ export class BigIntStatistics extends Statistics {
|
|
|
1441
1404
|
}
|
|
1442
1405
|
mode(argument1) {
|
|
1443
1406
|
if (this.isEmpty()) {
|
|
1444
|
-
return
|
|
1407
|
+
return 0;
|
|
1445
1408
|
}
|
|
1446
1409
|
try {
|
|
1447
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1448
|
-
return
|
|
1410
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1411
|
+
return useSynchronousNumericMode(mapper).collect(this.source());
|
|
1449
1412
|
}
|
|
1450
1413
|
catch (error) {
|
|
1451
1414
|
throw new Error("Uncaught error on mode.");
|
|
@@ -1453,11 +1416,11 @@ export class BigIntStatistics extends Statistics {
|
|
|
1453
1416
|
}
|
|
1454
1417
|
summate(argument1) {
|
|
1455
1418
|
if (this.isEmpty()) {
|
|
1456
|
-
return
|
|
1419
|
+
return 0;
|
|
1457
1420
|
}
|
|
1458
1421
|
try {
|
|
1459
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1460
|
-
return
|
|
1422
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1423
|
+
return useSynchronousNumericSummate(mapper).collect(this.source());
|
|
1461
1424
|
}
|
|
1462
1425
|
catch (error) {
|
|
1463
1426
|
throw new Error("Uncaught error on summate.");
|
|
@@ -1465,13 +1428,13 @@ export class BigIntStatistics extends Statistics {
|
|
|
1465
1428
|
}
|
|
1466
1429
|
quantile(quantile, argument1) {
|
|
1467
1430
|
if (this.isEmpty()) {
|
|
1468
|
-
return
|
|
1431
|
+
return 0;
|
|
1469
1432
|
}
|
|
1470
|
-
if (
|
|
1433
|
+
if (quantile < 0 || quantile > 1) {
|
|
1471
1434
|
throw new RangeError("Invalid quantile.");
|
|
1472
1435
|
}
|
|
1473
1436
|
try {
|
|
1474
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1437
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1475
1438
|
let count = Number(this.count());
|
|
1476
1439
|
let index = Math.floor(quantile * count);
|
|
1477
1440
|
if (index === count) {
|
|
@@ -1486,10 +1449,10 @@ export class BigIntStatistics extends Statistics {
|
|
|
1486
1449
|
}
|
|
1487
1450
|
interquartileRange(argument1) {
|
|
1488
1451
|
if (this.isEmpty()) {
|
|
1489
|
-
return
|
|
1452
|
+
return 0;
|
|
1490
1453
|
}
|
|
1491
1454
|
try {
|
|
1492
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1455
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1493
1456
|
let lower = this.quantile(0.25, mapper);
|
|
1494
1457
|
let upper = this.quantile(0.75, mapper);
|
|
1495
1458
|
return upper - lower;
|
|
@@ -1500,22 +1463,22 @@ export class BigIntStatistics extends Statistics {
|
|
|
1500
1463
|
}
|
|
1501
1464
|
skewness(argument1) {
|
|
1502
1465
|
if (this.isEmpty()) {
|
|
1503
|
-
return
|
|
1466
|
+
return 0;
|
|
1504
1467
|
}
|
|
1505
1468
|
try {
|
|
1506
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1469
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1507
1470
|
let mean = this.mean(mapper);
|
|
1508
1471
|
let standardDeviation = this.standardDeviation(mapper);
|
|
1509
|
-
if (standardDeviation ===
|
|
1510
|
-
return
|
|
1472
|
+
if (standardDeviation === 0) {
|
|
1473
|
+
return 0;
|
|
1511
1474
|
}
|
|
1512
1475
|
let data = this.toArray().map(item => mapper(item));
|
|
1513
|
-
let summate =
|
|
1476
|
+
let summate = 0;
|
|
1514
1477
|
for (let value of data) {
|
|
1515
|
-
let z = value - mean;
|
|
1516
|
-
summate += z
|
|
1478
|
+
let z = (value - mean) / standardDeviation;
|
|
1479
|
+
summate += Math.pow(z, 3);
|
|
1517
1480
|
}
|
|
1518
|
-
return summate /
|
|
1481
|
+
return summate / data.length;
|
|
1519
1482
|
}
|
|
1520
1483
|
catch (error) {
|
|
1521
1484
|
throw new Error("Uncaught error on skewness.");
|
|
@@ -1523,23 +1486,22 @@ export class BigIntStatistics extends Statistics {
|
|
|
1523
1486
|
}
|
|
1524
1487
|
kurtosis(argument1) {
|
|
1525
1488
|
if (this.isEmpty()) {
|
|
1526
|
-
return
|
|
1489
|
+
return 0;
|
|
1527
1490
|
}
|
|
1528
1491
|
try {
|
|
1529
|
-
let mapper = isFunction(argument1) ? argument1 :
|
|
1492
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1530
1493
|
let mean = this.mean(mapper);
|
|
1531
1494
|
let standardDeviation = this.standardDeviation(mapper);
|
|
1532
|
-
if (standardDeviation ===
|
|
1533
|
-
return
|
|
1495
|
+
if (standardDeviation === 0) {
|
|
1496
|
+
return 0;
|
|
1534
1497
|
}
|
|
1535
1498
|
let data = this.toArray().map(item => mapper(item));
|
|
1536
|
-
let summate =
|
|
1537
|
-
let count = data.length;
|
|
1499
|
+
let summate = 0;
|
|
1538
1500
|
for (let value of data) {
|
|
1539
|
-
let z = value - mean;
|
|
1540
|
-
summate += z
|
|
1501
|
+
let z = (value - mean) / standardDeviation;
|
|
1502
|
+
summate += Math.pow(z, 4);
|
|
1541
1503
|
}
|
|
1542
|
-
return summate /
|
|
1504
|
+
return summate / (data.length * data.length) - 3;
|
|
1543
1505
|
}
|
|
1544
1506
|
catch (error) {
|
|
1545
1507
|
throw new Error("Uncaught error on kurtosis.");
|
|
@@ -1547,13 +1509,13 @@ export class BigIntStatistics extends Statistics {
|
|
|
1547
1509
|
}
|
|
1548
1510
|
}
|
|
1549
1511
|
;
|
|
1550
|
-
export class
|
|
1551
|
-
WindowCollectable =
|
|
1512
|
+
export class SynchronousWindowCollectable extends SynchronousOrderedCollectable {
|
|
1513
|
+
WindowCollectable = SynchronousWindowCollectableSymbol;
|
|
1552
1514
|
constructor(parameter, comparator = useCompare) {
|
|
1553
1515
|
super(parameter, comparator);
|
|
1554
1516
|
Object.defineProperties(this, {
|
|
1555
|
-
"
|
|
1556
|
-
value:
|
|
1517
|
+
"SynchronousWindowCollectable": {
|
|
1518
|
+
value: SynchronousWindowCollectableSymbol,
|
|
1557
1519
|
writable: false,
|
|
1558
1520
|
enumerable: false,
|
|
1559
1521
|
configurable: false
|
|
@@ -1582,12 +1544,12 @@ export class WindowCollectable extends OrderedCollectable {
|
|
|
1582
1544
|
}
|
|
1583
1545
|
slide(size, step = 1n) {
|
|
1584
1546
|
if (size > 0n && step > 0n) {
|
|
1585
|
-
return new
|
|
1547
|
+
return new SynchronousSemantic((accepet, interrupt) => {
|
|
1586
1548
|
try {
|
|
1587
1549
|
let index = 0n;
|
|
1588
1550
|
for (let start = 0n; start < BigInt(this.buffer.length); start += step) {
|
|
1589
1551
|
let end = start + size;
|
|
1590
|
-
let inner = new
|
|
1552
|
+
let inner = new SynchronousSemantic((accept, interrupt) => {
|
|
1591
1553
|
for (let index = start; index < end && index < BigInt(this.buffer.length); index++) {
|
|
1592
1554
|
let indexed = this.buffer[Number(index)];
|
|
1593
1555
|
if (invalidate(indexed)) {
|