semantic-typescript 0.4.1 → 0.5.3
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/collector.d.ts +3 -9
- package/dist/collector.js +3 -22
- package/dist/factory.d.ts +72 -14
- package/dist/factory.js +441 -71
- package/dist/guard.d.ts +6 -10
- package/dist/guard.js +21 -20
- package/dist/hash.d.ts +1 -2
- package/dist/hash.js +9 -15
- package/dist/hook.d.ts +5 -1
- package/dist/hook.js +72 -19
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/main.d.ts +1 -0
- package/dist/main.js +4 -0
- package/dist/map.d.ts +4 -0
- package/dist/map.js +4 -6
- package/dist/node.d.ts +182 -0
- package/dist/node.js +918 -0
- package/dist/optional.d.ts +6 -3
- package/dist/optional.js +30 -8
- package/dist/semantic.d.ts +204 -4
- package/dist/semantic.js +1135 -13
- package/dist/set.js +1 -0
- package/dist/symbol.d.ts +1 -8
- package/dist/symbol.js +1 -8
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/dist/utility.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +492 -282
- package/dist/collectable.d.ts +0 -96
- package/dist/collectable.js +0 -554
- package/dist/statistics.d.ts +0 -97
- package/dist/statistics.js +0 -483
- package/dist/window.d.ts +0 -12
- package/dist/window.js +0 -72
package/dist/semantic.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isBigInt, isCollectable, isFunction, isIterable, isNumber, isSemantic } from "./guard";
|
|
1
|
+
import { useAnyMatch, useAllMatch, Collector, useCollect, useCount, useError, useFindAny, useFindAt, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray, useToMap, useToSet, useWrite, useFrequency, useNumericAverage, useNumericVariance, useNumericStandardDeviation, useNumericMedian, useNumericMode, useNumericSummate, useBigIntAverage, useBigIntVariance, useBigIntMedian, useBigIntMode, useBigIntSummate } from "./collector";
|
|
2
|
+
import { isBigInt, isCollectable, isCollector, isFunction, isIterable, isNumber, isObject, isSemantic, isString } from "./guard";
|
|
3
3
|
import { useHash } from "./hash";
|
|
4
|
-
import { useCompare } from "./hook";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { validate } from "./utility";
|
|
8
|
-
import { WindowCollectable } from "./window";
|
|
4
|
+
import { useCompare, useToBigInt, useToNumber } from "./hook";
|
|
5
|
+
import { AsyncCollectableSymbol, BigIntStatisticsSymbol, CollectableSymbol, NumericStatisticsSymbol, OrderedCollectableSymbol, SemanticSymbol, StatisticsSymbol, UnorderedCollectableSymbol, WindowCollectableSymbol } from "./symbol";
|
|
6
|
+
import { invalidate, validate } from "./utility";
|
|
9
7
|
export class Semantic {
|
|
10
8
|
generator;
|
|
11
9
|
Semantic = SemanticSymbol;
|
|
@@ -25,7 +23,6 @@ export class Semantic {
|
|
|
25
23
|
configurable: false
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
|
-
Object.freeze(this);
|
|
29
26
|
}
|
|
30
27
|
concat(other) {
|
|
31
28
|
if (isSemantic(other)) {
|
|
@@ -300,7 +297,7 @@ export class Semantic {
|
|
|
300
297
|
return new Semantic((accept, interrupt) => {
|
|
301
298
|
try {
|
|
302
299
|
this.generator((element, index) => {
|
|
303
|
-
accept(element, useHash(
|
|
300
|
+
accept(element, useHash(element, index));
|
|
304
301
|
}, interrupt);
|
|
305
302
|
}
|
|
306
303
|
catch (error) {
|
|
@@ -425,6 +422,14 @@ export class Semantic {
|
|
|
425
422
|
throw new Error("Uncaught error on toBigintStatistics.");
|
|
426
423
|
}
|
|
427
424
|
}
|
|
425
|
+
toEvent() {
|
|
426
|
+
try {
|
|
427
|
+
return new EventCollectable(this.generator);
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
throw new Error("Uncaught error on toEvent.");
|
|
431
|
+
}
|
|
432
|
+
}
|
|
428
433
|
toNumericStatistics() {
|
|
429
434
|
try {
|
|
430
435
|
return new NumericStatistics(this.generator);
|
|
@@ -446,7 +451,7 @@ export class Semantic {
|
|
|
446
451
|
return new UnorderedCollectable(this.generator);
|
|
447
452
|
}
|
|
448
453
|
catch (error) {
|
|
449
|
-
throw new Error(
|
|
454
|
+
throw new Error(String(error));
|
|
450
455
|
}
|
|
451
456
|
}
|
|
452
457
|
toWindow() {
|
|
@@ -501,6 +506,1123 @@ export class Semantic {
|
|
|
501
506
|
}
|
|
502
507
|
}
|
|
503
508
|
;
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
509
|
+
export class Collectable {
|
|
510
|
+
Collectable = CollectableSymbol;
|
|
511
|
+
constructor() {
|
|
512
|
+
Object.defineProperty(this, "Collectable", {
|
|
513
|
+
value: CollectableSymbol,
|
|
514
|
+
enumerable: false,
|
|
515
|
+
writable: false,
|
|
516
|
+
configurable: false
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
anyMatch(predicate) {
|
|
520
|
+
if (isFunction(predicate)) {
|
|
521
|
+
try {
|
|
522
|
+
return useAnyMatch(predicate).collect(this);
|
|
523
|
+
}
|
|
524
|
+
catch (error) {
|
|
525
|
+
throw new Error("Uncaught error on anyMatch.");
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
throw new TypeError("Predicate must be a function.");
|
|
529
|
+
}
|
|
530
|
+
allMatch(predicate) {
|
|
531
|
+
return useAllMatch(predicate).collect(this);
|
|
532
|
+
}
|
|
533
|
+
collect(argument1, argument2, argument3, argument4) {
|
|
534
|
+
try {
|
|
535
|
+
if (isCollector(argument1)) {
|
|
536
|
+
let collector = argument1;
|
|
537
|
+
return collector.collect(this);
|
|
538
|
+
}
|
|
539
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
540
|
+
let identity = argument1;
|
|
541
|
+
let accumulator = argument2;
|
|
542
|
+
let finisher = argument3;
|
|
543
|
+
return useCollect(identity, accumulator, finisher).collect(this);
|
|
544
|
+
}
|
|
545
|
+
if (isFunction(argument1) && isFunction(argument2) && isFunction(argument3) && isFunction(argument4)) {
|
|
546
|
+
let identity = argument1;
|
|
547
|
+
let interrupt = argument2;
|
|
548
|
+
let accumulator = argument3;
|
|
549
|
+
let finisher = argument4;
|
|
550
|
+
return useCollect(identity, interrupt, accumulator, finisher).collect(this);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
catch (error) {
|
|
554
|
+
throw new Error("Uncaught error on collect.");
|
|
555
|
+
}
|
|
556
|
+
throw new TypeError("Invalid arguments.");
|
|
557
|
+
}
|
|
558
|
+
count() {
|
|
559
|
+
return useCount().collect(this.source());
|
|
560
|
+
}
|
|
561
|
+
error(argument1, argument2, argument3) {
|
|
562
|
+
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
563
|
+
try {
|
|
564
|
+
useError().collect(this.source());
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
throw new Error("Uncaught error on error.");
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
571
|
+
try {
|
|
572
|
+
let accumulator = argument1;
|
|
573
|
+
useError(accumulator).collect(this.source());
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
throw new Error("Uncaught error on error.");
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
580
|
+
try {
|
|
581
|
+
let prefix = argument1;
|
|
582
|
+
let accumulator = argument2;
|
|
583
|
+
let suffix = argument3;
|
|
584
|
+
useError(prefix, accumulator, suffix).collect(this.source());
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
throw new Error("Uncaught error on error.");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
throw new TypeError("Invalid arguments.");
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
isEmpty() {
|
|
595
|
+
return this.count() === 0n;
|
|
596
|
+
}
|
|
597
|
+
findAny() {
|
|
598
|
+
try {
|
|
599
|
+
return useFindAny().collect(this.source());
|
|
600
|
+
}
|
|
601
|
+
catch (error) {
|
|
602
|
+
throw new Error("Uncaught error on findAny.");
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
findAt(index) {
|
|
606
|
+
if (isBigInt(index)) {
|
|
607
|
+
try {
|
|
608
|
+
return useFindAt(index).collect(this.source());
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
throw new Error("Uncaught error on findAt.");
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
else if (isNumber(index)) {
|
|
615
|
+
try {
|
|
616
|
+
return useFindAt(index).collect(this.source());
|
|
617
|
+
}
|
|
618
|
+
catch (error) {
|
|
619
|
+
throw new Error("Uncaught error on findAt.");
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
throw new TypeError("Index must be a bigint.");
|
|
623
|
+
}
|
|
624
|
+
findFirst() {
|
|
625
|
+
try {
|
|
626
|
+
return useFindFirst().collect(this.source());
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
throw new Error("Uncaught error on findFirst.");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
findLast() {
|
|
633
|
+
try {
|
|
634
|
+
return useFindLast().collect(this.source());
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
throw new Error("Uncaught error on findLast.");
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
findMaximum(argument1) {
|
|
641
|
+
try {
|
|
642
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
643
|
+
return useFindMaximum(comparator).collect(this.source());
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
throw new Error("Uncaught error on findMaximum.");
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
findMinimum(argument1) {
|
|
650
|
+
try {
|
|
651
|
+
let comparator = isFunction(argument1) ? argument1 : useCompare;
|
|
652
|
+
return useFindMinimum(comparator).collect(this.source());
|
|
653
|
+
}
|
|
654
|
+
catch (error) {
|
|
655
|
+
throw new Error("Uncaught error on findMinimum.");
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
forEach(action) {
|
|
659
|
+
if (isFunction(action)) {
|
|
660
|
+
try {
|
|
661
|
+
useForEach(action).collect(this);
|
|
662
|
+
}
|
|
663
|
+
catch (error) {
|
|
664
|
+
throw new Error("Uncaught error on forEach.");
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
throw new TypeError("Action must be a function.");
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
group(classifier) {
|
|
672
|
+
if (isFunction(classifier)) {
|
|
673
|
+
try {
|
|
674
|
+
return useGroup(classifier).collect(this.source());
|
|
675
|
+
}
|
|
676
|
+
catch (error) {
|
|
677
|
+
throw new Error("Uncaught error on group.");
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
throw new TypeError("Classifier must be a function.");
|
|
681
|
+
}
|
|
682
|
+
groupBy(keyExtractor, valueExtractor) {
|
|
683
|
+
if (isFunction(keyExtractor) && isFunction(valueExtractor)) {
|
|
684
|
+
try {
|
|
685
|
+
return useGroupBy(keyExtractor, valueExtractor).collect(this.source());
|
|
686
|
+
}
|
|
687
|
+
catch (error) {
|
|
688
|
+
throw new Error("Uncaught error on groupBy.");
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
throw new TypeError("Key and value extractors must be functions.");
|
|
692
|
+
}
|
|
693
|
+
join(argument1, argument2, argument3) {
|
|
694
|
+
if (invalidate(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
695
|
+
try {
|
|
696
|
+
return useJoin().collect(this.source());
|
|
697
|
+
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
throw new Error("Uncaught error on join.");
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
703
|
+
try {
|
|
704
|
+
let delimiter = argument1;
|
|
705
|
+
return useJoin(delimiter).collect(this.source());
|
|
706
|
+
}
|
|
707
|
+
catch (error) {
|
|
708
|
+
throw new Error("Uncaught error on join.");
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
712
|
+
try {
|
|
713
|
+
let prefix = argument1;
|
|
714
|
+
let accumulator = argument2;
|
|
715
|
+
let suffix = argument3;
|
|
716
|
+
return useJoin(prefix, accumulator, suffix).collect(this.source());
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
throw new Error("Uncaught error on join.");
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
else if (isString(argument1) && isString(argument2) && isString(argument3)) {
|
|
723
|
+
try {
|
|
724
|
+
let prefix = argument1;
|
|
725
|
+
let delimiter = argument2;
|
|
726
|
+
let suffix = argument3;
|
|
727
|
+
return useJoin(prefix, delimiter, suffix).collect(this.source());
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
throw new Error("Uncaught error on join.");
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
throw new TypeError("Invalid arguments.");
|
|
734
|
+
}
|
|
735
|
+
log(argument1, argument2, argument3) {
|
|
736
|
+
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
737
|
+
try {
|
|
738
|
+
let accumulator = argument1;
|
|
739
|
+
useLog(accumulator).collect(this.source());
|
|
740
|
+
}
|
|
741
|
+
catch (error) {
|
|
742
|
+
throw new Error("Uncaught error on log.");
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
|
|
746
|
+
try {
|
|
747
|
+
let prefix = argument1;
|
|
748
|
+
let accumulator = argument2;
|
|
749
|
+
let suffix = argument3;
|
|
750
|
+
useLog(prefix, accumulator, suffix).collect(this.source());
|
|
751
|
+
}
|
|
752
|
+
catch (error) {
|
|
753
|
+
throw new Error("Uncaught error on log.");
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
try {
|
|
758
|
+
useLog().collect(this.source());
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
throw new Error("Uncaught error on log.");
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
nonMatch(predicate) {
|
|
766
|
+
if (isFunction(predicate)) {
|
|
767
|
+
try {
|
|
768
|
+
return useNoneMatch(predicate).collect(this.source());
|
|
769
|
+
}
|
|
770
|
+
catch (error) {
|
|
771
|
+
throw new Error("Uncaught error on nonMatch.");
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
throw new TypeError("Predicate must be a function.");
|
|
775
|
+
}
|
|
776
|
+
partition(count) {
|
|
777
|
+
if (isBigInt(count)) {
|
|
778
|
+
try {
|
|
779
|
+
return usePartition(count).collect(this.source());
|
|
780
|
+
}
|
|
781
|
+
catch (error) {
|
|
782
|
+
throw new Error("Uncaught error on partition.");
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
throw new TypeError("Count must be a BigInt.");
|
|
786
|
+
}
|
|
787
|
+
partitionBy(classifier) {
|
|
788
|
+
if (isFunction(classifier)) {
|
|
789
|
+
try {
|
|
790
|
+
let collector = usePartitionBy(classifier);
|
|
791
|
+
return collector.collect(this.source());
|
|
792
|
+
}
|
|
793
|
+
catch (error) {
|
|
794
|
+
throw new Error("Uncaught error on partitionBy.");
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
throw new TypeError("Classifier must be a function.");
|
|
798
|
+
}
|
|
799
|
+
reduce(argument1, argument2, argument3) {
|
|
800
|
+
if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
|
|
801
|
+
try {
|
|
802
|
+
let accumulator = argument1;
|
|
803
|
+
return useReduce(accumulator).collect(this.source());
|
|
804
|
+
}
|
|
805
|
+
catch (error) {
|
|
806
|
+
throw new Error("Uncaught error on reduce.");
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
|
|
810
|
+
try {
|
|
811
|
+
let identity = argument1;
|
|
812
|
+
let accumulator = argument2;
|
|
813
|
+
return useReduce(identity, accumulator).collect(this.source());
|
|
814
|
+
}
|
|
815
|
+
catch (error) {
|
|
816
|
+
throw new Error("Uncaught error on reduce.");
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
|
|
820
|
+
try {
|
|
821
|
+
let identity = argument1;
|
|
822
|
+
let accumulator = argument2;
|
|
823
|
+
let finisher = argument3;
|
|
824
|
+
return useReduce(identity, accumulator, finisher).collect(this.source());
|
|
825
|
+
}
|
|
826
|
+
catch (error) {
|
|
827
|
+
throw new Error("Uncaught error on reduce.");
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
throw new TypeError("Invalid arguments.");
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
semantic() {
|
|
835
|
+
let source = this.source();
|
|
836
|
+
if (isFunction(source)) {
|
|
837
|
+
try {
|
|
838
|
+
return new Semantic(source);
|
|
839
|
+
}
|
|
840
|
+
catch (error) {
|
|
841
|
+
throw new Error("Uncaught error on semantic.");
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
throw new TypeError("Invalid source.");
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
toArray() {
|
|
849
|
+
try {
|
|
850
|
+
return useToArray().collect(this.source());
|
|
851
|
+
}
|
|
852
|
+
catch (error) {
|
|
853
|
+
throw new Error("Uncaught error on toArray.");
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
toMap(keyExtractor, valueExtractor = (element) => element) {
|
|
857
|
+
try {
|
|
858
|
+
return useToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
859
|
+
}
|
|
860
|
+
catch (error) {
|
|
861
|
+
throw new Error("Uncaught error on toMap.");
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
toSet() {
|
|
865
|
+
try {
|
|
866
|
+
return useToSet().collect(this.source());
|
|
867
|
+
}
|
|
868
|
+
catch (error) {
|
|
869
|
+
throw new Error("Uncaught error on toSet.");
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
write(argument1, argument2) {
|
|
873
|
+
if (isObject(argument1)) {
|
|
874
|
+
try {
|
|
875
|
+
let stream = argument1;
|
|
876
|
+
if (isFunction(argument2)) {
|
|
877
|
+
let accumulator = argument2;
|
|
878
|
+
return useWrite(stream, accumulator).collect(this.source());
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
return useWrite(stream).collect(this.source());
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
catch (error) {
|
|
885
|
+
throw new Error("Uncaught error on write.");
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
throw new TypeError("Invalid arguments.");
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
;
|
|
892
|
+
export class EventCollectable extends Collectable {
|
|
893
|
+
AsyncCollectable = AsyncCollectableSymbol;
|
|
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;
|
|
990
|
+
buffer;
|
|
991
|
+
constructor(argument1, argument2) {
|
|
992
|
+
super();
|
|
993
|
+
if (isFunction(argument1)) {
|
|
994
|
+
try {
|
|
995
|
+
if (isFunction(argument2)) {
|
|
996
|
+
let collector = useToArray();
|
|
997
|
+
this.buffer = collector.collect(argument1).sort(argument2).map((element, index) => {
|
|
998
|
+
return {
|
|
999
|
+
element: element,
|
|
1000
|
+
index: BigInt(index)
|
|
1001
|
+
};
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
let collector = useToArray();
|
|
1006
|
+
this.buffer = collector.collect(argument1).map((element, index) => {
|
|
1007
|
+
return {
|
|
1008
|
+
element: element,
|
|
1009
|
+
index: BigInt(index)
|
|
1010
|
+
};
|
|
1011
|
+
}).sort((a, b) => {
|
|
1012
|
+
return Number(a.index - b.index);
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
Object.defineProperties(this, {
|
|
1016
|
+
"OrderedCollectable": {
|
|
1017
|
+
value: OrderedCollectableSymbol,
|
|
1018
|
+
writable: false,
|
|
1019
|
+
enumerable: false,
|
|
1020
|
+
configurable: false
|
|
1021
|
+
},
|
|
1022
|
+
"buffer": {
|
|
1023
|
+
value: this.buffer,
|
|
1024
|
+
writable: false,
|
|
1025
|
+
enumerable: false,
|
|
1026
|
+
configurable: false
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
catch (error) {
|
|
1031
|
+
throw new Error("Uncaught error on creating buffer.");
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
throw new TypeError("Source must be an iterable or a generator function.");
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
*[Symbol.iterator]() {
|
|
1039
|
+
try {
|
|
1040
|
+
for (let indexed of this.buffer) {
|
|
1041
|
+
yield indexed.element;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
catch (error) {
|
|
1045
|
+
throw new Error("Uncaught error on Generator.");
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
async *[Symbol.asyncIterator]() {
|
|
1049
|
+
try {
|
|
1050
|
+
for (let indexed of this.buffer) {
|
|
1051
|
+
yield indexed.element;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
catch (error) {
|
|
1055
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
source() {
|
|
1059
|
+
try {
|
|
1060
|
+
return (accept, interrupt) => {
|
|
1061
|
+
for (let indexed of this.buffer) {
|
|
1062
|
+
if (interrupt(indexed.element, indexed.index)) {
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
accept(indexed.element, indexed.index);
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
catch (error) {
|
|
1070
|
+
throw new Error("Uncaught error on creating source.");
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
isEmpty() {
|
|
1074
|
+
return this.buffer.length === 0;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
;
|
|
1078
|
+
export class Statistics extends OrderedCollectable {
|
|
1079
|
+
Statistics = StatisticsSymbol;
|
|
1080
|
+
constructor(parameter, comparator) {
|
|
1081
|
+
super(parameter, comparator || useCompare);
|
|
1082
|
+
Object.defineProperties(this, {
|
|
1083
|
+
"Statistics": {
|
|
1084
|
+
value: StatisticsSymbol,
|
|
1085
|
+
enumerable: false,
|
|
1086
|
+
writable: false,
|
|
1087
|
+
configurable: false
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
*[Symbol.iterator]() {
|
|
1092
|
+
try {
|
|
1093
|
+
for (let indexed of this.buffer) {
|
|
1094
|
+
yield indexed.element;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
catch (error) {
|
|
1098
|
+
throw new Error("Uncaught error on Generator.");
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async *[Symbol.asyncIterator]() {
|
|
1102
|
+
try {
|
|
1103
|
+
for (let indexed of this.buffer) {
|
|
1104
|
+
yield indexed.element;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
catch (error) {
|
|
1108
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
count() {
|
|
1112
|
+
return BigInt(this.buffer.length);
|
|
1113
|
+
}
|
|
1114
|
+
frequency() {
|
|
1115
|
+
return useFrequency().collect(this.source());
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
;
|
|
1119
|
+
export class NumericStatistics extends Statistics {
|
|
1120
|
+
NumericStatistics = NumericStatisticsSymbol;
|
|
1121
|
+
constructor(parameter, comparator) {
|
|
1122
|
+
super(parameter, comparator || useCompare);
|
|
1123
|
+
Object.defineProperties(this, {
|
|
1124
|
+
"NumericStatistics": {
|
|
1125
|
+
value: NumericStatisticsSymbol,
|
|
1126
|
+
enumerable: false,
|
|
1127
|
+
writable: false,
|
|
1128
|
+
configurable: false
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
*[Symbol.iterator]() {
|
|
1133
|
+
try {
|
|
1134
|
+
for (let indexed of this.buffer) {
|
|
1135
|
+
yield indexed.element;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
catch (error) {
|
|
1139
|
+
throw new Error("Uncaught error on Generator.");
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
async *[Symbol.asyncIterator]() {
|
|
1143
|
+
try {
|
|
1144
|
+
for (let indexed of this.buffer) {
|
|
1145
|
+
yield indexed.element;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
catch (error) {
|
|
1149
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
average(mapper) {
|
|
1153
|
+
if (this.isEmpty()) {
|
|
1154
|
+
return 0;
|
|
1155
|
+
}
|
|
1156
|
+
try {
|
|
1157
|
+
if (isFunction(mapper)) {
|
|
1158
|
+
return useNumericAverage(mapper).collect(this.source());
|
|
1159
|
+
}
|
|
1160
|
+
return useNumericAverage().collect(this.source());
|
|
1161
|
+
}
|
|
1162
|
+
catch (error) {
|
|
1163
|
+
throw new Error("Uncaught error on average.");
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
range(argument1) {
|
|
1167
|
+
if (this.isEmpty()) {
|
|
1168
|
+
return 0;
|
|
1169
|
+
}
|
|
1170
|
+
try {
|
|
1171
|
+
if (this.count() === 1n) {
|
|
1172
|
+
return 0;
|
|
1173
|
+
}
|
|
1174
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1175
|
+
let count = this.buffer.length;
|
|
1176
|
+
let minimum = this.buffer[0].element;
|
|
1177
|
+
let maximum = this.buffer[count - 1].element;
|
|
1178
|
+
return mapper(maximum) - mapper(minimum);
|
|
1179
|
+
}
|
|
1180
|
+
catch (error) {
|
|
1181
|
+
throw new Error("Uncaught error on range.");
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
variance(argument1) {
|
|
1185
|
+
if (this.isEmpty() || this.count() === 1n) {
|
|
1186
|
+
return 0;
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1190
|
+
return useNumericVariance(mapper).collect(this.source());
|
|
1191
|
+
}
|
|
1192
|
+
catch (error) {
|
|
1193
|
+
throw new Error("Uncaught error on variance.");
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
standardDeviation(argument1) {
|
|
1197
|
+
try {
|
|
1198
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1199
|
+
return useNumericStandardDeviation(mapper).collect(this.source());
|
|
1200
|
+
}
|
|
1201
|
+
catch (error) {
|
|
1202
|
+
throw new Error("Uncaught error on standardDeviation.");
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
mean(argument1) {
|
|
1206
|
+
if (this.isEmpty()) {
|
|
1207
|
+
return 0;
|
|
1208
|
+
}
|
|
1209
|
+
try {
|
|
1210
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1211
|
+
return useNumericAverage(mapper).collect(this.source());
|
|
1212
|
+
}
|
|
1213
|
+
catch (error) {
|
|
1214
|
+
throw new Error("Uncaught error on mean.");
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
median(argument1) {
|
|
1218
|
+
if (this.isEmpty()) {
|
|
1219
|
+
return 0;
|
|
1220
|
+
}
|
|
1221
|
+
try {
|
|
1222
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1223
|
+
return useNumericMedian(mapper).collect(this.source());
|
|
1224
|
+
}
|
|
1225
|
+
catch (error) {
|
|
1226
|
+
throw new Error("Uncaught error on median.");
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
mode(argument1) {
|
|
1230
|
+
if (this.isEmpty()) {
|
|
1231
|
+
return 0;
|
|
1232
|
+
}
|
|
1233
|
+
try {
|
|
1234
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1235
|
+
return useNumericMode(mapper).collect(this.source());
|
|
1236
|
+
}
|
|
1237
|
+
catch (error) {
|
|
1238
|
+
throw new Error("Uncaught error on mode.");
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
summate(argument1) {
|
|
1242
|
+
if (this.isEmpty()) {
|
|
1243
|
+
return 0;
|
|
1244
|
+
}
|
|
1245
|
+
try {
|
|
1246
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1247
|
+
return useNumericSummate(mapper).collect(this.source());
|
|
1248
|
+
}
|
|
1249
|
+
catch (error) {
|
|
1250
|
+
throw new Error("Uncaught error on summate.");
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
quantile(quantile, argument1) {
|
|
1254
|
+
if (this.isEmpty()) {
|
|
1255
|
+
return 0;
|
|
1256
|
+
}
|
|
1257
|
+
if (quantile < 0 || quantile > 1) {
|
|
1258
|
+
throw new RangeError("Invalid quantile.");
|
|
1259
|
+
}
|
|
1260
|
+
try {
|
|
1261
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1262
|
+
let count = Number(this.count());
|
|
1263
|
+
let index = Math.floor(quantile * count);
|
|
1264
|
+
if (index === count) {
|
|
1265
|
+
index--;
|
|
1266
|
+
}
|
|
1267
|
+
let value = mapper(this.buffer[index].element);
|
|
1268
|
+
return value;
|
|
1269
|
+
}
|
|
1270
|
+
catch (error) {
|
|
1271
|
+
throw new Error("Uncaught error on quantile.");
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
interquartileRange(argument1) {
|
|
1275
|
+
if (this.isEmpty()) {
|
|
1276
|
+
return 0;
|
|
1277
|
+
}
|
|
1278
|
+
try {
|
|
1279
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1280
|
+
let lower = this.quantile(0.25, mapper);
|
|
1281
|
+
let upper = this.quantile(0.75, mapper);
|
|
1282
|
+
return upper - lower;
|
|
1283
|
+
}
|
|
1284
|
+
catch (error) {
|
|
1285
|
+
throw new Error("Uncaught error on interquartileRange.");
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
skewness(argument1) {
|
|
1289
|
+
if (this.isEmpty()) {
|
|
1290
|
+
return 0;
|
|
1291
|
+
}
|
|
1292
|
+
try {
|
|
1293
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1294
|
+
let mean = this.mean(mapper);
|
|
1295
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
1296
|
+
if (standardDeviation === 0) {
|
|
1297
|
+
return 0;
|
|
1298
|
+
}
|
|
1299
|
+
let data = this.toArray().map(item => mapper(item));
|
|
1300
|
+
let summate = 0;
|
|
1301
|
+
for (let value of data) {
|
|
1302
|
+
let z = (value - mean) / standardDeviation;
|
|
1303
|
+
summate += Math.pow(z, 3);
|
|
1304
|
+
}
|
|
1305
|
+
return summate / data.length;
|
|
1306
|
+
}
|
|
1307
|
+
catch (error) {
|
|
1308
|
+
throw new Error("Uncaught error on skewness.");
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
kurtosis(argument1) {
|
|
1312
|
+
if (this.isEmpty()) {
|
|
1313
|
+
return 0;
|
|
1314
|
+
}
|
|
1315
|
+
try {
|
|
1316
|
+
let mapper = isFunction(argument1) ? argument1 : useToNumber;
|
|
1317
|
+
let mean = this.mean(mapper);
|
|
1318
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
1319
|
+
if (standardDeviation === 0) {
|
|
1320
|
+
return 0;
|
|
1321
|
+
}
|
|
1322
|
+
let data = this.toArray().map(item => mapper(item));
|
|
1323
|
+
let summate = 0;
|
|
1324
|
+
for (let value of data) {
|
|
1325
|
+
let z = (value - mean) / standardDeviation;
|
|
1326
|
+
summate += Math.pow(z, 4);
|
|
1327
|
+
}
|
|
1328
|
+
return summate / (data.length * data.length) - 3;
|
|
1329
|
+
}
|
|
1330
|
+
catch (error) {
|
|
1331
|
+
throw new Error("Uncaught error on kurtosis.");
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
;
|
|
1336
|
+
export class BigIntStatistics extends Statistics {
|
|
1337
|
+
BigIntStatistics = BigIntStatisticsSymbol;
|
|
1338
|
+
constructor(parameter, comparator) {
|
|
1339
|
+
super(parameter, comparator || useCompare);
|
|
1340
|
+
Object.defineProperties(this, {
|
|
1341
|
+
"BigIntStatistics": {
|
|
1342
|
+
value: BigIntStatisticsSymbol,
|
|
1343
|
+
enumerable: false,
|
|
1344
|
+
writable: false,
|
|
1345
|
+
configurable: false
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
*[Symbol.iterator]() {
|
|
1350
|
+
try {
|
|
1351
|
+
for (let indexed of this.buffer) {
|
|
1352
|
+
yield indexed.element;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
catch (error) {
|
|
1356
|
+
throw new Error("Uncaught error on Generator.");
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
async *[Symbol.asyncIterator]() {
|
|
1360
|
+
try {
|
|
1361
|
+
for (let indexed of this.buffer) {
|
|
1362
|
+
yield indexed.element;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
catch (error) {
|
|
1366
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
average(argument1) {
|
|
1370
|
+
if (this.isEmpty()) {
|
|
1371
|
+
return 0n;
|
|
1372
|
+
}
|
|
1373
|
+
try {
|
|
1374
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1375
|
+
return useBigIntAverage(mapper).collect(this.source());
|
|
1376
|
+
}
|
|
1377
|
+
catch (error) {
|
|
1378
|
+
throw new Error("Uncaught error on average.");
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
range(argument1) {
|
|
1382
|
+
if (this.isEmpty()) {
|
|
1383
|
+
return 0n;
|
|
1384
|
+
}
|
|
1385
|
+
try {
|
|
1386
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1387
|
+
let count = this.buffer.length;
|
|
1388
|
+
let minimum = this.buffer[0].element;
|
|
1389
|
+
let maximum = this.buffer[count - 1].element;
|
|
1390
|
+
return mapper(maximum) - mapper(minimum);
|
|
1391
|
+
}
|
|
1392
|
+
catch (error) {
|
|
1393
|
+
throw new Error("Uncaught error on range.");
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
variance(argument1) {
|
|
1397
|
+
if (this.isEmpty() || this.count() === 1n) {
|
|
1398
|
+
return 0n;
|
|
1399
|
+
}
|
|
1400
|
+
try {
|
|
1401
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1402
|
+
return useBigIntVariance(mapper).collect(this.source());
|
|
1403
|
+
}
|
|
1404
|
+
catch (error) {
|
|
1405
|
+
throw new Error("Uncaught error on variance.");
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
standardDeviation(argument1) {
|
|
1409
|
+
try {
|
|
1410
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1411
|
+
let variance = this.variance(mapper);
|
|
1412
|
+
return BigInt(Math.sqrt(Number(variance)));
|
|
1413
|
+
}
|
|
1414
|
+
catch (error) {
|
|
1415
|
+
throw new Error("Uncaught error on standardDeviation.");
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
mean(argument1) {
|
|
1419
|
+
if (this.isEmpty()) {
|
|
1420
|
+
return 0n;
|
|
1421
|
+
}
|
|
1422
|
+
try {
|
|
1423
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1424
|
+
return useBigIntAverage(mapper).collect(this.source());
|
|
1425
|
+
}
|
|
1426
|
+
catch (error) {
|
|
1427
|
+
throw new Error("Uncaught error on mean.");
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
median(argument1) {
|
|
1431
|
+
if (this.isEmpty()) {
|
|
1432
|
+
return 0n;
|
|
1433
|
+
}
|
|
1434
|
+
try {
|
|
1435
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1436
|
+
return useBigIntMedian(mapper).collect(this.source());
|
|
1437
|
+
}
|
|
1438
|
+
catch (error) {
|
|
1439
|
+
throw new Error("Uncaught error on median.");
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
mode(argument1) {
|
|
1443
|
+
if (this.isEmpty()) {
|
|
1444
|
+
return 0n;
|
|
1445
|
+
}
|
|
1446
|
+
try {
|
|
1447
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1448
|
+
return useBigIntMode(mapper).collect(this.source());
|
|
1449
|
+
}
|
|
1450
|
+
catch (error) {
|
|
1451
|
+
throw new Error("Uncaught error on mode.");
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
summate(argument1) {
|
|
1455
|
+
if (this.isEmpty()) {
|
|
1456
|
+
return 0n;
|
|
1457
|
+
}
|
|
1458
|
+
try {
|
|
1459
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1460
|
+
return useBigIntSummate(mapper).collect(this.source());
|
|
1461
|
+
}
|
|
1462
|
+
catch (error) {
|
|
1463
|
+
throw new Error("Uncaught error on summate.");
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
quantile(quantile, argument1) {
|
|
1467
|
+
if (this.isEmpty()) {
|
|
1468
|
+
return 0n;
|
|
1469
|
+
}
|
|
1470
|
+
if (typeof quantile !== "number" || quantile < 0 || quantile > 1) {
|
|
1471
|
+
throw new RangeError("Invalid quantile.");
|
|
1472
|
+
}
|
|
1473
|
+
try {
|
|
1474
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1475
|
+
let count = Number(this.count());
|
|
1476
|
+
let index = Math.floor(quantile * count);
|
|
1477
|
+
if (index === count) {
|
|
1478
|
+
index--;
|
|
1479
|
+
}
|
|
1480
|
+
let value = mapper(this.buffer[index].element);
|
|
1481
|
+
return value;
|
|
1482
|
+
}
|
|
1483
|
+
catch (error) {
|
|
1484
|
+
throw new Error("Uncaught error on quantile.");
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
interquartileRange(argument1) {
|
|
1488
|
+
if (this.isEmpty()) {
|
|
1489
|
+
return 0n;
|
|
1490
|
+
}
|
|
1491
|
+
try {
|
|
1492
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1493
|
+
let lower = this.quantile(0.25, mapper);
|
|
1494
|
+
let upper = this.quantile(0.75, mapper);
|
|
1495
|
+
return upper - lower;
|
|
1496
|
+
}
|
|
1497
|
+
catch (error) {
|
|
1498
|
+
throw new Error("Uncaught error on interquartileRange.");
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
skewness(argument1) {
|
|
1502
|
+
if (this.isEmpty()) {
|
|
1503
|
+
return 0n;
|
|
1504
|
+
}
|
|
1505
|
+
try {
|
|
1506
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1507
|
+
let mean = this.mean(mapper);
|
|
1508
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
1509
|
+
if (standardDeviation === 0n) {
|
|
1510
|
+
return 0n;
|
|
1511
|
+
}
|
|
1512
|
+
let data = this.toArray().map(item => mapper(item));
|
|
1513
|
+
let summate = 0n;
|
|
1514
|
+
for (let value of data) {
|
|
1515
|
+
let z = value - mean;
|
|
1516
|
+
summate += z * z * z;
|
|
1517
|
+
}
|
|
1518
|
+
return summate / BigInt(data.length);
|
|
1519
|
+
}
|
|
1520
|
+
catch (error) {
|
|
1521
|
+
throw new Error("Uncaught error on skewness.");
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
kurtosis(argument1) {
|
|
1525
|
+
if (this.isEmpty()) {
|
|
1526
|
+
return 0n;
|
|
1527
|
+
}
|
|
1528
|
+
try {
|
|
1529
|
+
let mapper = isFunction(argument1) ? argument1 : useToBigInt;
|
|
1530
|
+
let mean = this.mean(mapper);
|
|
1531
|
+
let standardDeviation = this.standardDeviation(mapper);
|
|
1532
|
+
if (standardDeviation === 0n) {
|
|
1533
|
+
return 0n;
|
|
1534
|
+
}
|
|
1535
|
+
let data = this.toArray().map(item => mapper(item));
|
|
1536
|
+
let summate = 0n;
|
|
1537
|
+
let count = data.length;
|
|
1538
|
+
for (let value of data) {
|
|
1539
|
+
let z = value - mean;
|
|
1540
|
+
summate += z * z * z * z;
|
|
1541
|
+
}
|
|
1542
|
+
return summate / BigInt(count * count) - 3n;
|
|
1543
|
+
}
|
|
1544
|
+
catch (error) {
|
|
1545
|
+
throw new Error("Uncaught error on kurtosis.");
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
;
|
|
1550
|
+
export class WindowCollectable extends OrderedCollectable {
|
|
1551
|
+
WindowCollectable = WindowCollectableSymbol;
|
|
1552
|
+
constructor(parameter, comparator = useCompare) {
|
|
1553
|
+
super(parameter, comparator);
|
|
1554
|
+
Object.defineProperties(this, {
|
|
1555
|
+
"WindowCollectable": {
|
|
1556
|
+
value: WindowCollectableSymbol,
|
|
1557
|
+
writable: false,
|
|
1558
|
+
enumerable: false,
|
|
1559
|
+
configurable: false
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
*[Symbol.iterator]() {
|
|
1564
|
+
try {
|
|
1565
|
+
for (let indexed of this.buffer) {
|
|
1566
|
+
yield indexed.element;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
catch (error) {
|
|
1570
|
+
throw new Error("Uncaught error on Generator.");
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
async *[Symbol.asyncIterator]() {
|
|
1574
|
+
try {
|
|
1575
|
+
for (let indexed of this.buffer) {
|
|
1576
|
+
yield indexed.element;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
catch (error) {
|
|
1580
|
+
throw new Error("Uncaught error on AsyncGenerator.");
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
slide(size, step = 1n) {
|
|
1584
|
+
if (size > 0n && step > 0n) {
|
|
1585
|
+
return new Semantic((accepet, interrupt) => {
|
|
1586
|
+
try {
|
|
1587
|
+
let index = 0n;
|
|
1588
|
+
for (let start = 0n; start < BigInt(this.buffer.length); start += step) {
|
|
1589
|
+
let end = start + size;
|
|
1590
|
+
let inner = new Semantic((accept, interrupt) => {
|
|
1591
|
+
for (let index = start; index < end && index < BigInt(this.buffer.length); index++) {
|
|
1592
|
+
let indexed = this.buffer[Number(index)];
|
|
1593
|
+
if (invalidate(indexed)) {
|
|
1594
|
+
continue;
|
|
1595
|
+
}
|
|
1596
|
+
if (interrupt(indexed.element, index)) {
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
accept(indexed.element, index);
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
if (interrupt(inner, index)) {
|
|
1603
|
+
break;
|
|
1604
|
+
}
|
|
1605
|
+
accepet(inner, index);
|
|
1606
|
+
index++;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
catch (error) {
|
|
1610
|
+
throw new Error("Uncaught error on slide.");
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
throw new RangeError("Invalid arguments.");
|
|
1615
|
+
}
|
|
1616
|
+
tumble(size) {
|
|
1617
|
+
if (isBigInt(size) && size > 0n) {
|
|
1618
|
+
try {
|
|
1619
|
+
return this.slide(size, size);
|
|
1620
|
+
}
|
|
1621
|
+
catch (error) {
|
|
1622
|
+
throw new Error("Uncaught error on tumble.");
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
throw new RangeError("Invalid arguments.");
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
;
|