semantic-typescript 0.3.8 → 0.5.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/collectable.d.ts +119 -1
- package/dist/collectable.js +624 -21
- package/dist/collector.d.ts +94 -50
- package/dist/collector.js +128 -110
- package/dist/factory.d.ts +23 -35
- package/dist/factory.js +162 -68
- package/dist/guard.d.ts +43 -28
- package/dist/guard.js +144 -65
- package/dist/hash.d.ts +13 -0
- package/dist/hash.js +205 -0
- package/dist/hook.d.ts +16 -4
- package/dist/hook.js +19 -15
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/map.d.ts +76 -0
- package/dist/map.js +253 -0
- package/dist/node.d.ts +182 -0
- package/dist/node.js +918 -0
- package/dist/optional.d.ts +3 -0
- package/dist/optional.js +26 -23
- package/dist/semantic.d.ts +1 -3
- package/dist/semantic.js +43 -50
- package/dist/set.d.ts +19 -0
- package/dist/set.js +65 -0
- package/dist/statistics.js +21 -15
- package/dist/symbol.d.ts +14 -0
- package/dist/symbol.js +14 -0
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/dist/utility.d.ts +8 -1
- package/dist/utility.js +9 -0
- package/dist/window.js +7 -5
- package/package.json +1 -5
- package/readme.cn.md +381 -636
- package/readme.md +3 -1
package/dist/collectable.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Collector, useAllMatch, useAnyMatch, useBigIntAverage, useBigIntMedian, useBigIntMode, useBigIntSummate, useBigIntVariance, useCollect, useCount, useError, useFindAny, useFindAt, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useFrequency, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, useNumericAverage, useNumericMedian, useNumericMode, useNumericStandardDeviation, useNumericSummate, useNumericVariance, usePartition, usePartitionBy, useReduce, useToArray, useToHashMap, useToHashSet, useToMap, useToSet, useWrite } from "./collector";
|
|
2
|
+
import { from } from "./factory";
|
|
3
|
+
import { isBigInt, isCollector, isFunction, isNumber, isObject, isString } from "./guard";
|
|
4
|
+
import { useCompare, useToBigInt, useToNumber } from "./hook";
|
|
5
|
+
import { HashMap } from "./map";
|
|
4
6
|
import { Optional } from "./optional";
|
|
5
7
|
import { Semantic } from "./semantic";
|
|
6
|
-
import { CollectableSymbol, OrderedCollectableSymbol, UnorderedCollectableSymbol } from "./symbol";
|
|
8
|
+
import { BigIntStatisticsSymbol, CollectableSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
|
|
7
9
|
import { invalidate, validate } from "./utility";
|
|
8
10
|
export class Collectable {
|
|
9
11
|
Collectable = CollectableSymbol;
|
|
@@ -102,6 +104,25 @@ export class Collectable {
|
|
|
102
104
|
throw new Error("Uncaught error on findAny.");
|
|
103
105
|
}
|
|
104
106
|
}
|
|
107
|
+
findAt(index) {
|
|
108
|
+
if (isBigInt(index)) {
|
|
109
|
+
try {
|
|
110
|
+
return useFindAt(index).collect(this.source());
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw new Error("Uncaught error on findAt.");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (isNumber(index)) {
|
|
117
|
+
try {
|
|
118
|
+
return useFindAt(index).collect(this.source());
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw new Error("Uncaught error on findAt.");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
throw new TypeError("Index must be a bigint.");
|
|
125
|
+
}
|
|
105
126
|
findFirst() {
|
|
106
127
|
try {
|
|
107
128
|
return useFindFirst().collect(this.source());
|
|
@@ -334,7 +355,7 @@ export class Collectable {
|
|
|
334
355
|
throw new Error("Uncaught error on toArray.");
|
|
335
356
|
}
|
|
336
357
|
}
|
|
337
|
-
toMap(keyExtractor, valueExtractor) {
|
|
358
|
+
toMap(keyExtractor, valueExtractor = (element) => element) {
|
|
338
359
|
try {
|
|
339
360
|
return useToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
340
361
|
}
|
|
@@ -342,6 +363,14 @@ export class Collectable {
|
|
|
342
363
|
throw new Error("Uncaught error on toMap.");
|
|
343
364
|
}
|
|
344
365
|
}
|
|
366
|
+
toHashMap(keyExtractor, valueExtractor = (element) => element) {
|
|
367
|
+
try {
|
|
368
|
+
return useToHashMap(keyExtractor, valueExtractor).collect(this.source());
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
throw new Error("Uncaught error on toHashMap.");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
345
374
|
toSet() {
|
|
346
375
|
try {
|
|
347
376
|
return useToSet().collect(this.source());
|
|
@@ -350,6 +379,14 @@ export class Collectable {
|
|
|
350
379
|
throw new Error("Uncaught error on toSet.");
|
|
351
380
|
}
|
|
352
381
|
}
|
|
382
|
+
toHashSet() {
|
|
383
|
+
try {
|
|
384
|
+
return useToHashSet().collect(this.source());
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
throw new Error("Uncaught error on toHashSet.");
|
|
388
|
+
}
|
|
389
|
+
}
|
|
353
390
|
write(argument1, argument2) {
|
|
354
391
|
if (isObject(argument1)) {
|
|
355
392
|
try {
|
|
@@ -372,14 +409,17 @@ export class Collectable {
|
|
|
372
409
|
;
|
|
373
410
|
Object.freeze(Collectable);
|
|
374
411
|
Object.freeze(Collectable.prototype);
|
|
375
|
-
Object.freeze(Object.getPrototypeOf(Collectable
|
|
412
|
+
Object.freeze(Object.getPrototypeOf(Collectable));
|
|
376
413
|
export class UnorderedCollectable extends Collectable {
|
|
377
414
|
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
378
|
-
|
|
415
|
+
buffer = new HashMap();
|
|
379
416
|
constructor(argument1) {
|
|
380
417
|
super();
|
|
381
418
|
if (isFunction(argument1)) {
|
|
382
|
-
|
|
419
|
+
let generator = argument1;
|
|
420
|
+
generator((element, index) => {
|
|
421
|
+
this.buffer.set(index, element);
|
|
422
|
+
}, () => false);
|
|
383
423
|
Object.defineProperties(this, {
|
|
384
424
|
"UnorderedCollectable": {
|
|
385
425
|
value: UnorderedCollectableSymbol,
|
|
@@ -388,7 +428,7 @@ export class UnorderedCollectable extends Collectable {
|
|
|
388
428
|
configurable: false
|
|
389
429
|
},
|
|
390
430
|
"generator": {
|
|
391
|
-
value:
|
|
431
|
+
value: argument1,
|
|
392
432
|
writable: false,
|
|
393
433
|
enumerable: false,
|
|
394
434
|
configurable: false
|
|
@@ -401,12 +441,20 @@ export class UnorderedCollectable extends Collectable {
|
|
|
401
441
|
}
|
|
402
442
|
}
|
|
403
443
|
source() {
|
|
404
|
-
return
|
|
444
|
+
return (accept, interrupt) => {
|
|
445
|
+
for (let [index, element] of this.buffer) {
|
|
446
|
+
if (interrupt(element, index)) {
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
accept(element, index);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
405
452
|
}
|
|
406
453
|
*[Symbol.iterator]() {
|
|
407
454
|
try {
|
|
408
|
-
let
|
|
409
|
-
|
|
455
|
+
for (let [_index, element] of this.buffer) {
|
|
456
|
+
yield element;
|
|
457
|
+
}
|
|
410
458
|
}
|
|
411
459
|
catch (error) {
|
|
412
460
|
throw new Error("Uncaught error on Generator.");
|
|
@@ -414,8 +462,9 @@ export class UnorderedCollectable extends Collectable {
|
|
|
414
462
|
}
|
|
415
463
|
async *[Symbol.asyncIterator]() {
|
|
416
464
|
try {
|
|
417
|
-
let
|
|
418
|
-
|
|
465
|
+
for (let [_index, element] of this.buffer) {
|
|
466
|
+
yield element;
|
|
467
|
+
}
|
|
419
468
|
}
|
|
420
469
|
catch (error) {
|
|
421
470
|
throw new Error("Uncaught error on AsyncGenerator.");
|
|
@@ -425,7 +474,7 @@ export class UnorderedCollectable extends Collectable {
|
|
|
425
474
|
;
|
|
426
475
|
Object.freeze(UnorderedCollectable);
|
|
427
476
|
Object.freeze(UnorderedCollectable.prototype);
|
|
428
|
-
Object.freeze(Object.getPrototypeOf(UnorderedCollectable
|
|
477
|
+
Object.freeze(Object.getPrototypeOf(UnorderedCollectable));
|
|
429
478
|
export class OrderedCollectable extends Collectable {
|
|
430
479
|
OrderedCollectable = OrderedCollectableSymbol;
|
|
431
480
|
buffer;
|
|
@@ -467,7 +516,6 @@ export class OrderedCollectable extends Collectable {
|
|
|
467
516
|
configurable: false
|
|
468
517
|
}
|
|
469
518
|
});
|
|
470
|
-
Object.freeze(this);
|
|
471
519
|
}
|
|
472
520
|
catch (error) {
|
|
473
521
|
throw new Error("Uncaught error on creating buffer.");
|
|
@@ -479,8 +527,9 @@ export class OrderedCollectable extends Collectable {
|
|
|
479
527
|
}
|
|
480
528
|
*[Symbol.iterator]() {
|
|
481
529
|
try {
|
|
482
|
-
let
|
|
483
|
-
|
|
530
|
+
for (let indexed of this.buffer) {
|
|
531
|
+
yield indexed.element;
|
|
532
|
+
}
|
|
484
533
|
}
|
|
485
534
|
catch (error) {
|
|
486
535
|
throw new Error("Uncaught error on Generator.");
|
|
@@ -488,8 +537,9 @@ export class OrderedCollectable extends Collectable {
|
|
|
488
537
|
}
|
|
489
538
|
async *[Symbol.asyncIterator]() {
|
|
490
539
|
try {
|
|
491
|
-
let
|
|
492
|
-
|
|
540
|
+
for (let indexed of this.buffer) {
|
|
541
|
+
yield indexed.element;
|
|
542
|
+
}
|
|
493
543
|
}
|
|
494
544
|
catch (error) {
|
|
495
545
|
throw new Error("Uncaught error on AsyncGenerator.");
|
|
@@ -517,4 +567,557 @@ export class OrderedCollectable extends Collectable {
|
|
|
517
567
|
;
|
|
518
568
|
Object.freeze(OrderedCollectable);
|
|
519
569
|
Object.freeze(OrderedCollectable.prototype);
|
|
520
|
-
Object.freeze(Object.getPrototypeOf(OrderedCollectable
|
|
570
|
+
Object.freeze(Object.getPrototypeOf(OrderedCollectable));
|
|
571
|
+
export class Statistics extends OrderedCollectable {
|
|
572
|
+
Statistics = StatisticsSymbol;
|
|
573
|
+
constructor(parameter, comparator) {
|
|
574
|
+
super(parameter, comparator || useCompare);
|
|
575
|
+
Object.defineProperties(this, {
|
|
576
|
+
"Statistics": {
|
|
577
|
+
value: StatisticsSymbol,
|
|
578
|
+
enumerable: false,
|
|
579
|
+
writable: false,
|
|
580
|
+
configurable: false
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
Object.freeze(this);
|
|
584
|
+
}
|
|
585
|
+
*[Symbol.iterator]() {
|
|
586
|
+
try {
|
|
587
|
+
for (let indexed of this.buffer) {
|
|
588
|
+
yield indexed.element;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
catch (error) {
|
|
592
|
+
throw new Error("Uncaught error on Generator.");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
async *[Symbol.asyncIterator]() {
|
|
596
|
+
try {
|
|
597
|
+
for (let indexed of this.buffer) {
|
|
598
|
+
yield indexed.element;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
catch (error) {
|
|
602
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
count() {
|
|
606
|
+
return BigInt(this.buffer.length);
|
|
607
|
+
}
|
|
608
|
+
frequency() {
|
|
609
|
+
return useFrequency().collect(this.source());
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
;
|
|
613
|
+
Object.freeze(Statistics);
|
|
614
|
+
Object.freeze(Statistics.prototype);
|
|
615
|
+
Object.freeze(Object.getPrototypeOf(Statistics));
|
|
616
|
+
export class NumericStatistics extends Statistics {
|
|
617
|
+
NumericStatistics = NumericStatisticsSymbol;
|
|
618
|
+
constructor(parameter, comparator) {
|
|
619
|
+
super(parameter, comparator || useCompare);
|
|
620
|
+
Object.defineProperties(this, {
|
|
621
|
+
"NumericStatistics": {
|
|
622
|
+
value: NumericStatisticsSymbol,
|
|
623
|
+
enumerable: false,
|
|
624
|
+
writable: false,
|
|
625
|
+
configurable: false
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
Object.freeze(this);
|
|
629
|
+
}
|
|
630
|
+
*[Symbol.iterator]() {
|
|
631
|
+
try {
|
|
632
|
+
for (let indexed of this.buffer) {
|
|
633
|
+
yield indexed.element;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
throw new Error("Uncaught error on Generator.");
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
async *[Symbol.asyncIterator]() {
|
|
641
|
+
try {
|
|
642
|
+
for (let indexed of this.buffer) {
|
|
643
|
+
yield indexed.element;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
average(mapper) {
|
|
651
|
+
if (this.isEmpty()) {
|
|
652
|
+
return 0;
|
|
653
|
+
}
|
|
654
|
+
try {
|
|
655
|
+
if (isFunction(mapper)) {
|
|
656
|
+
return useNumericAverage(mapper).collect(this.source());
|
|
657
|
+
}
|
|
658
|
+
return useNumericAverage().collect(this.source());
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
throw new Error("Uncaught error on average.");
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
range(argument1) {
|
|
665
|
+
if (this.isEmpty()) {
|
|
666
|
+
return 0;
|
|
667
|
+
}
|
|
668
|
+
try {
|
|
669
|
+
if (this.count() === 1n) {
|
|
670
|
+
return 0;
|
|
671
|
+
}
|
|
672
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
673
|
+
let count = this.buffer.length;
|
|
674
|
+
let minimum = this.buffer[0].element;
|
|
675
|
+
let maximum = this.buffer[count - 1].element;
|
|
676
|
+
return mapper(maximum) - mapper(minimum);
|
|
677
|
+
}
|
|
678
|
+
catch (error) {
|
|
679
|
+
throw new Error("Uncaught error on range.");
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
variance(argument1) {
|
|
683
|
+
if (this.isEmpty() || this.count() === 1n) {
|
|
684
|
+
return 0;
|
|
685
|
+
}
|
|
686
|
+
try {
|
|
687
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
688
|
+
return useNumericVariance(mapper).collect(this.source());
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
throw new Error("Uncaught error on variance.");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
standardDeviation(argument1) {
|
|
695
|
+
try {
|
|
696
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
697
|
+
return useNumericStandardDeviation(mapper).collect(this.source());
|
|
698
|
+
}
|
|
699
|
+
catch (error) {
|
|
700
|
+
throw new Error("Uncaught error on standardDeviation.");
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
mean(argument1) {
|
|
704
|
+
if (this.isEmpty()) {
|
|
705
|
+
return 0;
|
|
706
|
+
}
|
|
707
|
+
try {
|
|
708
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
709
|
+
return useNumericAverage(mapper).collect(this.source());
|
|
710
|
+
}
|
|
711
|
+
catch (error) {
|
|
712
|
+
throw new Error("Uncaught error on mean.");
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
median(argument1) {
|
|
716
|
+
if (this.isEmpty()) {
|
|
717
|
+
return 0;
|
|
718
|
+
}
|
|
719
|
+
try {
|
|
720
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
721
|
+
return useNumericMedian(mapper).collect(this.source());
|
|
722
|
+
}
|
|
723
|
+
catch (error) {
|
|
724
|
+
throw new Error("Uncaught error on median.");
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
mode(argument1) {
|
|
728
|
+
if (this.isEmpty()) {
|
|
729
|
+
return 0;
|
|
730
|
+
}
|
|
731
|
+
try {
|
|
732
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
733
|
+
return useNumericMode(mapper).collect(this.source());
|
|
734
|
+
}
|
|
735
|
+
catch (error) {
|
|
736
|
+
throw new Error("Uncaught error on mode.");
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
summate(argument1) {
|
|
740
|
+
if (this.isEmpty()) {
|
|
741
|
+
return 0;
|
|
742
|
+
}
|
|
743
|
+
try {
|
|
744
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
745
|
+
return useNumericSummate(mapper).collect(this.source());
|
|
746
|
+
}
|
|
747
|
+
catch (error) {
|
|
748
|
+
throw new Error("Uncaught error on summate.");
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
quantile(quantile, argument1) {
|
|
752
|
+
if (this.isEmpty()) {
|
|
753
|
+
return 0;
|
|
754
|
+
}
|
|
755
|
+
if (quantile < 0 || quantile > 1) {
|
|
756
|
+
throw new RangeError("Invalid quantile.");
|
|
757
|
+
}
|
|
758
|
+
try {
|
|
759
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
760
|
+
let count = Number(this.count());
|
|
761
|
+
let index = Math.floor(quantile * count);
|
|
762
|
+
if (index === count) {
|
|
763
|
+
index--;
|
|
764
|
+
}
|
|
765
|
+
let value = mapper(this.buffer[index].element);
|
|
766
|
+
return value;
|
|
767
|
+
}
|
|
768
|
+
catch (error) {
|
|
769
|
+
throw new Error("Uncaught error on quantile.");
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
interquartileRange(argument1) {
|
|
773
|
+
if (this.isEmpty()) {
|
|
774
|
+
return 0;
|
|
775
|
+
}
|
|
776
|
+
try {
|
|
777
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
778
|
+
let lower = this.quantile(0.25, mapper);
|
|
779
|
+
let upper = this.quantile(0.75, mapper);
|
|
780
|
+
return upper - lower;
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
throw new Error("Uncaught error on interquartileRange.");
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
skewness(argument1) {
|
|
787
|
+
if (this.isEmpty()) {
|
|
788
|
+
return 0;
|
|
789
|
+
}
|
|
790
|
+
try {
|
|
791
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
792
|
+
let mean = this.mean(mapper);
|
|
793
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
794
|
+
if (standardDeviation === 0) {
|
|
795
|
+
return 0;
|
|
796
|
+
}
|
|
797
|
+
let data = this.toArray().map(item => mapper(item));
|
|
798
|
+
let summate = 0;
|
|
799
|
+
for (let value of data) {
|
|
800
|
+
let z = (value - mean) / standardDeviation;
|
|
801
|
+
summate += Math.pow(z, 3);
|
|
802
|
+
}
|
|
803
|
+
return summate / data.length;
|
|
804
|
+
}
|
|
805
|
+
catch (error) {
|
|
806
|
+
throw new Error("Uncaught error on skewness.");
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
kurtosis(argument1) {
|
|
810
|
+
if (this.isEmpty()) {
|
|
811
|
+
return 0;
|
|
812
|
+
}
|
|
813
|
+
try {
|
|
814
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
815
|
+
let mean = this.mean(mapper);
|
|
816
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
817
|
+
if (standardDeviation === 0) {
|
|
818
|
+
return 0;
|
|
819
|
+
}
|
|
820
|
+
let data = this.toArray().map(item => mapper(item));
|
|
821
|
+
let summate = 0;
|
|
822
|
+
for (let value of data) {
|
|
823
|
+
let z = (value - mean) / standardDeviation;
|
|
824
|
+
summate += Math.pow(z, 4);
|
|
825
|
+
}
|
|
826
|
+
return summate / (data.length * data.length) - 3;
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
throw new Error("Uncaught error on kurtosis.");
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
;
|
|
834
|
+
Object.freeze(NumericStatistics);
|
|
835
|
+
Object.freeze(NumericStatistics.prototype);
|
|
836
|
+
Object.freeze(Object.getPrototypeOf(NumericStatistics));
|
|
837
|
+
export class BigIntStatistics extends Statistics {
|
|
838
|
+
BigIntStatistics = BigIntStatisticsSymbol;
|
|
839
|
+
constructor(parameter, comparator) {
|
|
840
|
+
super(parameter, comparator || useCompare);
|
|
841
|
+
Object.defineProperties(this, {
|
|
842
|
+
"BigIntStatistics": {
|
|
843
|
+
value: BigIntStatisticsSymbol,
|
|
844
|
+
enumerable: false,
|
|
845
|
+
writable: false,
|
|
846
|
+
configurable: false
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
Object.freeze(this);
|
|
850
|
+
}
|
|
851
|
+
*[Symbol.iterator]() {
|
|
852
|
+
try {
|
|
853
|
+
for (let indexed of this.buffer) {
|
|
854
|
+
yield indexed.element;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
catch (error) {
|
|
858
|
+
throw new Error("Uncaught error on Generator.");
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
async *[Symbol.asyncIterator]() {
|
|
862
|
+
try {
|
|
863
|
+
for (let indexed of this.buffer) {
|
|
864
|
+
yield indexed.element;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
catch (error) {
|
|
868
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
average(argument1) {
|
|
872
|
+
if (this.isEmpty()) {
|
|
873
|
+
return 0n;
|
|
874
|
+
}
|
|
875
|
+
try {
|
|
876
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
877
|
+
return useBigIntAverage(mapper).collect(this.source());
|
|
878
|
+
}
|
|
879
|
+
catch (error) {
|
|
880
|
+
throw new Error("Uncaught error on average.");
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
range(argument1) {
|
|
884
|
+
if (this.isEmpty()) {
|
|
885
|
+
return 0n;
|
|
886
|
+
}
|
|
887
|
+
try {
|
|
888
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
889
|
+
let count = this.buffer.length;
|
|
890
|
+
let minimum = this.buffer[0].element;
|
|
891
|
+
let maximum = this.buffer[count - 1].element;
|
|
892
|
+
return mapper(maximum) - mapper(minimum);
|
|
893
|
+
}
|
|
894
|
+
catch (error) {
|
|
895
|
+
throw new Error("Uncaught error on range.");
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
variance(argument1) {
|
|
899
|
+
if (this.isEmpty() || this.count() === 1n) {
|
|
900
|
+
return 0n;
|
|
901
|
+
}
|
|
902
|
+
try {
|
|
903
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
904
|
+
return useBigIntVariance(mapper).collect(this.source());
|
|
905
|
+
}
|
|
906
|
+
catch (error) {
|
|
907
|
+
throw new Error("Uncaught error on variance.");
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
standardDeviation(argument1) {
|
|
911
|
+
try {
|
|
912
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
913
|
+
let variance = this.variance(mapper);
|
|
914
|
+
return BigInt(Math.sqrt(Number(variance)));
|
|
915
|
+
}
|
|
916
|
+
catch (error) {
|
|
917
|
+
throw new Error("Uncaught error on standardDeviation.");
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
mean(argument1) {
|
|
921
|
+
if (this.isEmpty()) {
|
|
922
|
+
return 0n;
|
|
923
|
+
}
|
|
924
|
+
try {
|
|
925
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
926
|
+
return useBigIntAverage(mapper).collect(this.source());
|
|
927
|
+
}
|
|
928
|
+
catch (error) {
|
|
929
|
+
throw new Error("Uncaught error on mean.");
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
median(argument1) {
|
|
933
|
+
if (this.isEmpty()) {
|
|
934
|
+
return 0n;
|
|
935
|
+
}
|
|
936
|
+
try {
|
|
937
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
938
|
+
return useBigIntMedian(mapper).collect(this.source());
|
|
939
|
+
}
|
|
940
|
+
catch (error) {
|
|
941
|
+
throw new Error("Uncaught error on median.");
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
mode(argument1) {
|
|
945
|
+
if (this.isEmpty()) {
|
|
946
|
+
return 0n;
|
|
947
|
+
}
|
|
948
|
+
try {
|
|
949
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
950
|
+
return useBigIntMode(mapper).collect(this.source());
|
|
951
|
+
}
|
|
952
|
+
catch (error) {
|
|
953
|
+
throw new Error("Uncaught error on mode.");
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
summate(argument1) {
|
|
957
|
+
if (this.isEmpty()) {
|
|
958
|
+
return 0n;
|
|
959
|
+
}
|
|
960
|
+
try {
|
|
961
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
962
|
+
return useBigIntSummate(mapper).collect(this.source());
|
|
963
|
+
}
|
|
964
|
+
catch (error) {
|
|
965
|
+
throw new Error("Uncaught error on summate.");
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
quantile(quantile, argument1) {
|
|
969
|
+
if (this.isEmpty()) {
|
|
970
|
+
return 0n;
|
|
971
|
+
}
|
|
972
|
+
if (typeof quantile !== "number" || quantile < 0 || quantile > 1) {
|
|
973
|
+
throw new RangeError("Invalid quantile.");
|
|
974
|
+
}
|
|
975
|
+
try {
|
|
976
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
977
|
+
let count = Number(this.count());
|
|
978
|
+
let index = Math.floor(quantile * count);
|
|
979
|
+
if (index === count) {
|
|
980
|
+
index--;
|
|
981
|
+
}
|
|
982
|
+
let value = mapper(this.buffer[index].element);
|
|
983
|
+
return value;
|
|
984
|
+
}
|
|
985
|
+
catch (error) {
|
|
986
|
+
throw new Error("Uncaught error on quantile.");
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
interquartileRange(argument1) {
|
|
990
|
+
if (this.isEmpty()) {
|
|
991
|
+
return 0n;
|
|
992
|
+
}
|
|
993
|
+
try {
|
|
994
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
995
|
+
let lower = this.quantile(0.25, mapper);
|
|
996
|
+
let upper = this.quantile(0.75, mapper);
|
|
997
|
+
return upper - lower;
|
|
998
|
+
}
|
|
999
|
+
catch (error) {
|
|
1000
|
+
throw new Error("Uncaught error on interquartileRange.");
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
skewness(argument1) {
|
|
1004
|
+
if (this.isEmpty()) {
|
|
1005
|
+
return 0n;
|
|
1006
|
+
}
|
|
1007
|
+
try {
|
|
1008
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1009
|
+
let mean = this.mean(mapper);
|
|
1010
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
1011
|
+
if (standardDeviation === 0n) {
|
|
1012
|
+
return 0n;
|
|
1013
|
+
}
|
|
1014
|
+
let data = this.toArray().map(item => mapper(item));
|
|
1015
|
+
let summate = 0n;
|
|
1016
|
+
for (let value of data) {
|
|
1017
|
+
let z = value - mean;
|
|
1018
|
+
summate += z * z * z;
|
|
1019
|
+
}
|
|
1020
|
+
return summate / BigInt(data.length);
|
|
1021
|
+
}
|
|
1022
|
+
catch (error) {
|
|
1023
|
+
throw new Error("Uncaught error on skewness.");
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
kurtosis(argument1) {
|
|
1027
|
+
if (this.isEmpty()) {
|
|
1028
|
+
return 0n;
|
|
1029
|
+
}
|
|
1030
|
+
try {
|
|
1031
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1032
|
+
let mean = this.mean(mapper);
|
|
1033
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
1034
|
+
if (standardDeviation === 0n) {
|
|
1035
|
+
return 0n;
|
|
1036
|
+
}
|
|
1037
|
+
let data = this.toArray().map(item => mapper(item));
|
|
1038
|
+
let summate = 0n;
|
|
1039
|
+
let count = data.length;
|
|
1040
|
+
for (let value of data) {
|
|
1041
|
+
let z = value - mean;
|
|
1042
|
+
summate += z * z * z * z;
|
|
1043
|
+
}
|
|
1044
|
+
return summate / BigInt(count * count) - 3n;
|
|
1045
|
+
}
|
|
1046
|
+
catch (error) {
|
|
1047
|
+
throw new Error("Uncaught error on kurtosis.");
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
;
|
|
1052
|
+
Object.freeze(BigIntStatistics);
|
|
1053
|
+
Object.freeze(BigIntStatistics.prototype);
|
|
1054
|
+
Object.freeze(Object.getPrototypeOf(BigIntStatistics));
|
|
1055
|
+
export class WindowCollectable extends OrderedCollectable {
|
|
1056
|
+
WindowCollectable = WindowCollectableSymbol;
|
|
1057
|
+
constructor(parameter, comparator = useCompare) {
|
|
1058
|
+
super(parameter, comparator);
|
|
1059
|
+
Object.defineProperties(this, {
|
|
1060
|
+
"WindowCollectable": {
|
|
1061
|
+
value: WindowCollectableSymbol,
|
|
1062
|
+
writable: false,
|
|
1063
|
+
enumerable: false,
|
|
1064
|
+
configurable: false
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
Object.freeze(this);
|
|
1068
|
+
}
|
|
1069
|
+
*[Symbol.iterator]() {
|
|
1070
|
+
try {
|
|
1071
|
+
for (let indexed of this.buffer) {
|
|
1072
|
+
yield indexed.element;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
catch (error) {
|
|
1076
|
+
throw new Error("Uncaught error on Generator.");
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
async *[Symbol.asyncIterator]() {
|
|
1080
|
+
try {
|
|
1081
|
+
for (let indexed of this.buffer) {
|
|
1082
|
+
yield indexed.element;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
catch (error) {
|
|
1086
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
slide(size, step = 1n) {
|
|
1090
|
+
if (size > 0n && step > 0n) {
|
|
1091
|
+
try {
|
|
1092
|
+
let source = this.toArray();
|
|
1093
|
+
let windows = [];
|
|
1094
|
+
let windowStartIndex = 0n;
|
|
1095
|
+
while (windowStartIndex < BigInt(source.length)) {
|
|
1096
|
+
let windowEnd = windowStartIndex + size;
|
|
1097
|
+
let window = source.slice(Number(windowStartIndex), Number(windowEnd));
|
|
1098
|
+
if (window.length > 0) {
|
|
1099
|
+
windows.push(window);
|
|
1100
|
+
}
|
|
1101
|
+
windowStartIndex += step;
|
|
1102
|
+
}
|
|
1103
|
+
return from(windows).map((window) => from(window));
|
|
1104
|
+
}
|
|
1105
|
+
catch (error) {
|
|
1106
|
+
throw new Error("Invalid arguments.");
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
throw new RangeError("Invalid arguments.");
|
|
1110
|
+
}
|
|
1111
|
+
tumble(size) {
|
|
1112
|
+
try {
|
|
1113
|
+
return this.slide(size, size);
|
|
1114
|
+
}
|
|
1115
|
+
catch (error) {
|
|
1116
|
+
throw new Error("Invalid arguments.");
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
;
|
|
1121
|
+
Object.freeze(WindowCollectable);
|
|
1122
|
+
Object.freeze(WindowCollectable.prototype);
|
|
1123
|
+
Object.freeze(Object.getPrototypeOf(WindowCollectable));
|