semantic-typescript 0.4.1 → 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 +108 -2
- package/dist/collectable.js +585 -16
- package/dist/collector.d.ts +3 -0
- package/dist/collector.js +3 -3
- package/dist/factory.d.ts +14 -0
- package/dist/factory.js +159 -1
- package/dist/guard.d.ts +14 -5
- package/dist/guard.js +68 -7
- package/dist/hash.d.ts +1 -2
- package/dist/hash.js +9 -15
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -5
- package/dist/map.d.ts +4 -0
- package/dist/map.js +6 -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 +18 -0
- package/dist/semantic.d.ts +1 -3
- package/dist/semantic.js +2 -4
- package/dist/set.js +1 -0
- package/dist/statistics.js +7 -7
- package/dist/symbol.d.ts +8 -2
- package/dist/symbol.js +8 -2
- package/dist/tree.d.ts +82 -0
- package/dist/tree.js +257 -0
- package/package.json +1 -1
package/dist/collectable.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Collector, useAllMatch, useAnyMatch, useCollect, useCount, useError, useFindAny, useFindAt, useFindFirst, useFindLast, useFindMaximum, useFindMinimum, useForEach, useGroup, useGroupBy, useJoin, useLog, useNoneMatch, usePartition, usePartitionBy, useReduce, useToArray,
|
|
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";
|
|
2
3
|
import { isBigInt, isCollector, isFunction, isNumber, isObject, isString } from "./guard";
|
|
3
|
-
import { useCompare } from "./hook";
|
|
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;
|
|
@@ -353,7 +355,7 @@ export class Collectable {
|
|
|
353
355
|
throw new Error("Uncaught error on toArray.");
|
|
354
356
|
}
|
|
355
357
|
}
|
|
356
|
-
toMap(keyExtractor, valueExtractor) {
|
|
358
|
+
toMap(keyExtractor, valueExtractor = (element) => element) {
|
|
357
359
|
try {
|
|
358
360
|
return useToMap(keyExtractor, valueExtractor).collect(this.source());
|
|
359
361
|
}
|
|
@@ -361,7 +363,7 @@ export class Collectable {
|
|
|
361
363
|
throw new Error("Uncaught error on toMap.");
|
|
362
364
|
}
|
|
363
365
|
}
|
|
364
|
-
toHashMap(keyExtractor, valueExtractor) {
|
|
366
|
+
toHashMap(keyExtractor, valueExtractor = (element) => element) {
|
|
365
367
|
try {
|
|
366
368
|
return useToHashMap(keyExtractor, valueExtractor).collect(this.source());
|
|
367
369
|
}
|
|
@@ -410,11 +412,14 @@ Object.freeze(Collectable.prototype);
|
|
|
410
412
|
Object.freeze(Object.getPrototypeOf(Collectable));
|
|
411
413
|
export class UnorderedCollectable extends Collectable {
|
|
412
414
|
UnorderedCollectable = UnorderedCollectableSymbol;
|
|
413
|
-
|
|
415
|
+
buffer = new HashMap();
|
|
414
416
|
constructor(argument1) {
|
|
415
417
|
super();
|
|
416
418
|
if (isFunction(argument1)) {
|
|
417
|
-
|
|
419
|
+
let generator = argument1;
|
|
420
|
+
generator((element, index) => {
|
|
421
|
+
this.buffer.set(index, element);
|
|
422
|
+
}, () => false);
|
|
418
423
|
Object.defineProperties(this, {
|
|
419
424
|
"UnorderedCollectable": {
|
|
420
425
|
value: UnorderedCollectableSymbol,
|
|
@@ -436,12 +441,20 @@ export class UnorderedCollectable extends Collectable {
|
|
|
436
441
|
}
|
|
437
442
|
}
|
|
438
443
|
source() {
|
|
439
|
-
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
|
+
};
|
|
440
452
|
}
|
|
441
453
|
*[Symbol.iterator]() {
|
|
442
454
|
try {
|
|
443
|
-
let
|
|
444
|
-
|
|
455
|
+
for (let [_index, element] of this.buffer) {
|
|
456
|
+
yield element;
|
|
457
|
+
}
|
|
445
458
|
}
|
|
446
459
|
catch (error) {
|
|
447
460
|
throw new Error("Uncaught error on Generator.");
|
|
@@ -449,8 +462,9 @@ export class UnorderedCollectable extends Collectable {
|
|
|
449
462
|
}
|
|
450
463
|
async *[Symbol.asyncIterator]() {
|
|
451
464
|
try {
|
|
452
|
-
let
|
|
453
|
-
|
|
465
|
+
for (let [_index, element] of this.buffer) {
|
|
466
|
+
yield element;
|
|
467
|
+
}
|
|
454
468
|
}
|
|
455
469
|
catch (error) {
|
|
456
470
|
throw new Error("Uncaught error on AsyncGenerator.");
|
|
@@ -513,8 +527,9 @@ export class OrderedCollectable extends Collectable {
|
|
|
513
527
|
}
|
|
514
528
|
*[Symbol.iterator]() {
|
|
515
529
|
try {
|
|
516
|
-
let
|
|
517
|
-
|
|
530
|
+
for (let indexed of this.buffer) {
|
|
531
|
+
yield indexed.element;
|
|
532
|
+
}
|
|
518
533
|
}
|
|
519
534
|
catch (error) {
|
|
520
535
|
throw new Error("Uncaught error on Generator.");
|
|
@@ -522,8 +537,9 @@ export class OrderedCollectable extends Collectable {
|
|
|
522
537
|
}
|
|
523
538
|
async *[Symbol.asyncIterator]() {
|
|
524
539
|
try {
|
|
525
|
-
let
|
|
526
|
-
|
|
540
|
+
for (let indexed of this.buffer) {
|
|
541
|
+
yield indexed.element;
|
|
542
|
+
}
|
|
527
543
|
}
|
|
528
544
|
catch (error) {
|
|
529
545
|
throw new Error("Uncaught error on AsyncGenerator.");
|
|
@@ -552,3 +568,556 @@ export class OrderedCollectable extends Collectable {
|
|
|
552
568
|
Object.freeze(OrderedCollectable);
|
|
553
569
|
Object.freeze(OrderedCollectable.prototype);
|
|
554
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));
|
package/dist/collector.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ interface UseGroup {
|
|
|
94
94
|
}
|
|
95
95
|
export declare let useGroup: UseGroup;
|
|
96
96
|
interface UseGroupBy {
|
|
97
|
+
<E, K>(keyExtractor: Functional<E, K>): Collector<E, Map<K, E[]>, Map<K, E[]>>;
|
|
97
98
|
<E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Collector<E, Map<K, V[]>, Map<K, V[]>>;
|
|
98
99
|
<E, K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Collector<E, Map<K, V[]>, Map<K, V[]>>;
|
|
99
100
|
}
|
|
@@ -131,11 +132,13 @@ interface UseReduce {
|
|
|
131
132
|
export declare let useReduce: UseReduce;
|
|
132
133
|
export declare let useToArray: <E>() => Collector<E, E[], E[]>;
|
|
133
134
|
interface UseToMap {
|
|
135
|
+
<E, K>(keyExtractor: Functional<E, K>): Collector<E, Map<K, E>, Map<K, E>>;
|
|
134
136
|
<E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Collector<E, Map<K, V>, Map<K, V>>;
|
|
135
137
|
<E, K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Collector<E, Map<K, V>, Map<K, V>>;
|
|
136
138
|
}
|
|
137
139
|
export declare let useToMap: UseToMap;
|
|
138
140
|
interface UseToHashMap {
|
|
141
|
+
<E, K>(keyExtractor: Functional<E, K>): Collector<E, HashMap<K, E>, HashMap<K, E>>;
|
|
139
142
|
<E, K, V>(keyExtractor: Functional<E, K>, valueExtractor: Functional<E, V>): Collector<E, HashMap<K, V>, HashMap<K, V>>;
|
|
140
143
|
<E, K, V>(keyExtractor: BiFunctional<E, bigint, K>, valueExtractor: BiFunctional<E, bigint, V>): Collector<E, HashMap<K, V>, HashMap<K, V>>;
|
|
141
144
|
}
|