semantic-typescript 0.8.0 → 1.0.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.
@@ -1,3 +1,4 @@
1
+ import { Optional } from "../optional";
1
2
  import type { BiFunctional, BiPredicate, Functional, Predicate, Supplier, TriFunctional, TriPredicate, Consumer, BiConsumer, Comparator, AsynchronousGenerator } from "../utility";
2
3
  export declare class AsynchronousCollector<E, A, R> {
3
4
  protected identity: Supplier<A>;
@@ -58,10 +59,15 @@ interface UseAsynchronousError {
58
59
  }
59
60
  export declare let useAsynchronousError: UseAsynchronousError;
60
61
  interface UseAsynchronousFindAt {
62
+ <E>(index: number): AsynchronousCollector<E, Optional<E>, Promise<E>>;
63
+ <E>(index: bigint): AsynchronousCollector<E, Optional<E>, Promise<E>>;
64
+ }
65
+ export declare let useAsynchronousFindAt: UseAsynchronousFindAt;
66
+ interface UseAsynchronousFindNegativeAt {
61
67
  <E>(index: number): AsynchronousCollector<E, Array<E>, Promise<E>>;
62
68
  <E>(index: bigint): AsynchronousCollector<E, Array<E>, Promise<E>>;
63
69
  }
64
- export declare let useAsynchronousFindAt: UseAsynchronousFindAt;
70
+ export declare let useAsynchronousFindNegativeAt: UseAsynchronousFindNegativeAt;
65
71
  export declare let useAsynchronousFindFirst: <E>() => AsynchronousCollector<E, Array<E>, Promise<E>>;
66
72
  export declare let useAsynchronousFindAny: <E>() => AsynchronousCollector<E, Array<E>, Promise<E>>;
67
73
  export declare let useAsynchronousFindLast: <E>() => AsynchronousCollector<E, Array<E>, Promise<E>>;
@@ -1,5 +1,6 @@
1
1
  import { isFunction, isNumber, isBigInt, isBoolean, isString, isObject, isAsyncIterable, isAsyncFunction } from "../guard";
2
2
  import { useCompare, useToBigInt, useToNumber } from "../hook";
3
+ import { Optional } from "../optional";
3
4
  import { AsynchronousCollectorSymbol } from "../symbol";
4
5
  import { invalidate, validate } from "../utility";
5
6
  export class AsynchronousCollector {
@@ -229,25 +230,45 @@ export let useAsynchronousError = (argument1, argument2, argument3) => {
229
230
  export let useAsynchronousFindAt = (index) => {
230
231
  let target = useToBigInt(index);
231
232
  if (target < 0n) {
232
- return AsynchronousCollector.full(() => [], (accumulator, element) => {
233
- accumulator.push(element);
234
- return accumulator;
235
- }, (accumulator) => {
236
- if (accumulator.length === 0) {
237
- return Promise.reject(new Error("No element found."));
238
- }
239
- let limited = (((BigInt(accumulator.length)) % target) + target) % target;
240
- return Promise.resolve(accumulator[Number(limited)]);
233
+ throw new Error("Use \"useAsynchronousFindNegativeAt\" for negative index.");
234
+ }
235
+ return AsynchronousCollector.shortable(Optional.empty, (_element, _index, accumulator) => accumulator.isPresent(), (accumulator, element, index) => {
236
+ if (target === index) {
237
+ return Optional.of(element);
238
+ }
239
+ return accumulator;
240
+ }, (a) => {
241
+ return new Promise((resolve, reject) => {
242
+ a.ifPresent(resolve, reject);
241
243
  });
244
+ });
245
+ };
246
+ ;
247
+ export let useAsynchronousFindNegativeAt = (index) => {
248
+ let target = useToBigInt(index);
249
+ if (target > -1n) {
250
+ throw new Error("Use \"useAsynchronousFindAt\" for none-negative index.");
242
251
  }
243
- return AsynchronousCollector.shortable(() => [], (_element, _index, accumulator) => BigInt(accumulator.length) - 1n === target, (accumulator, element) => {
252
+ return AsynchronousCollector.full(() => [], (accumulator, element) => {
244
253
  accumulator.push(element);
245
254
  return accumulator;
246
255
  }, (accumulator) => {
247
- if (accumulator.length === 0) {
248
- return Promise.reject(new Error("No element found."));
249
- }
250
- return Promise.resolve(accumulator[Number(target)]);
256
+ return new Promise((resolve, reject) => {
257
+ if (accumulator.length > 0) {
258
+ let count = BigInt(accumulator.length);
259
+ let limit = (((target) % count) + count) % count;
260
+ let element = accumulator.at(Number(limit));
261
+ if (validate(element)) {
262
+ resolve(element);
263
+ }
264
+ else {
265
+ reject("Element could not be found with given index.");
266
+ }
267
+ }
268
+ else {
269
+ reject("Not element to be found.");
270
+ }
271
+ });
251
272
  });
252
273
  };
253
274
  export let useAsynchronousFindFirst = () => {
@@ -80,6 +80,8 @@ export declare abstract class AsynchronousCollectable<E> implements AsyncIterabl
80
80
  findAny(): Promise<E>;
81
81
  findAt(index: number): Promise<E>;
82
82
  findAt(index: bigint): Promise<E>;
83
+ findNegativeAt(index: number): Promise<E>;
84
+ findNegativeAt(index: bigint): Promise<E>;
83
85
  findFirst(): Promise<E>;
84
86
  findLast(): Promise<E>;
85
87
  findMaximum(): Promise<E>;
@@ -1,4 +1,4 @@
1
- import { useAsynchronousAnyMatch, useAsynchronousAllMatch, useAsynchronousCollect, useAsynchronousCount, useAsynchronousError, useAsynchronousFindAny, useAsynchronousFindAt, useAsynchronousFindFirst, useAsynchronousFindLast, useAsynchronousFindMaximum, useAsynchronousFindMinimum, useAsynchronousForEach, useAsynchronousGroup, useAsynchronousGroupBy, useAsynchronousJoin, useAsynchronousLog, useAsynchronousNoneMatch, useAsynchronousPartition, useAsynchronousPartitionBy, useAsynchronousReduce, useAsynchronousToArray, useAsynchronousToMap, useAsynchronousToSet, useAsynchronousWrite, useAsynchronousFrequency, useAsynchronousBigIntAverage, useAsynchronousBigIntMedian, useAsynchronousBigIntMode, useAsynchronousBigIntSummate, useAsynchronousBigIntVariance, useAsynchronousNumericAverage, useAsynchronousNumericMedian, useAsynchronousNumericMode, useAsynchronousNumericStandardDeviation, useAsynchronousNumericSummate, useAsynchronousNumericVariance } from "./collector";
1
+ import { useAsynchronousAnyMatch, useAsynchronousAllMatch, useAsynchronousCollect, useAsynchronousCount, useAsynchronousError, useAsynchronousFindAny, useAsynchronousFindAt, useAsynchronousFindFirst, useAsynchronousFindLast, useAsynchronousFindMaximum, useAsynchronousFindMinimum, useAsynchronousForEach, useAsynchronousGroup, useAsynchronousGroupBy, useAsynchronousJoin, useAsynchronousLog, useAsynchronousNoneMatch, useAsynchronousPartition, useAsynchronousPartitionBy, useAsynchronousReduce, useAsynchronousToArray, useAsynchronousToMap, useAsynchronousToSet, useAsynchronousWrite, useAsynchronousFrequency, useAsynchronousBigIntAverage, useAsynchronousBigIntMedian, useAsynchronousBigIntMode, useAsynchronousBigIntSummate, useAsynchronousBigIntVariance, useAsynchronousNumericAverage, useAsynchronousNumericMedian, useAsynchronousNumericMode, useAsynchronousNumericStandardDeviation, useAsynchronousNumericSummate, useAsynchronousNumericVariance, useAsynchronousFindNegativeAt } from "./collector";
2
2
  import { isFunction, isAsynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isAsynchronousCollectable, isAsyncIterable, isAsynchronousCollector } from "../guard";
3
3
  import { useHash } from "../hash";
4
4
  import { useCompare, useToBigInt, useToNumber } from "../hook";
@@ -450,14 +450,14 @@ export class AsynchronousSemantic {
450
450
  }
451
451
  }
452
452
  catch (error) {
453
- throw new Error("Uncaught error on toAsynchronousCollectable.");
453
+ throw error;
454
454
  }
455
455
  }
456
456
  try {
457
457
  return new AsynchronousUnorderedCollectable(this.generator);
458
458
  }
459
459
  catch (error) {
460
- throw new Error("Uncaught error on toAsynchronousCollectable.");
460
+ throw error;
461
461
  }
462
462
  }
463
463
  toBigintStatistics() {
@@ -465,7 +465,7 @@ export class AsynchronousSemantic {
465
465
  return new AsynchronousBigIntStatistics(this.generator);
466
466
  }
467
467
  catch (error) {
468
- throw new Error("Uncaught error on toBigintStatistics.");
468
+ throw error;
469
469
  }
470
470
  }
471
471
  toNumericStatistics() {
@@ -473,7 +473,7 @@ export class AsynchronousSemantic {
473
473
  return new AsynchronousNumericStatistics(this.generator);
474
474
  }
475
475
  catch (error) {
476
- throw new Error("Uncaught error on toNumericStatistics.");
476
+ throw error;
477
477
  }
478
478
  }
479
479
  toOrdered() {
@@ -481,7 +481,7 @@ export class AsynchronousSemantic {
481
481
  return new AsynchronousOrderedCollectable(this.generator);
482
482
  }
483
483
  catch (error) {
484
- throw new Error("Uncaught error on toOrdered.");
484
+ throw error;
485
485
  }
486
486
  }
487
487
  toUnordered() {
@@ -497,7 +497,7 @@ export class AsynchronousSemantic {
497
497
  return new AsynchronousWindowCollectable(this.generator);
498
498
  }
499
499
  catch (error) {
500
- throw new Error("Uncaught error on toWindow.");
500
+ throw error;
501
501
  }
502
502
  }
503
503
  translate(argument1) {
@@ -510,7 +510,7 @@ export class AsynchronousSemantic {
510
510
  }, interrupt);
511
511
  }
512
512
  catch (error) {
513
- throw new Error("Uncaught error on translate.");
513
+ throw error;
514
514
  }
515
515
  });
516
516
  }
@@ -523,7 +523,7 @@ export class AsynchronousSemantic {
523
523
  }, interrupt);
524
524
  }
525
525
  catch (error) {
526
- throw new Error("Uncaught error on translate.");
526
+ throw error;
527
527
  }
528
528
  });
529
529
  }
@@ -536,7 +536,7 @@ export class AsynchronousSemantic {
536
536
  }, interrupt);
537
537
  }
538
538
  catch (error) {
539
- throw new Error("Uncaught error on translate.");
539
+ throw error;
540
540
  }
541
541
  });
542
542
  }
@@ -566,7 +566,7 @@ export class AsynchronousCollectable {
566
566
  return await useAsynchronousAnyMatch(predicate).collect(this.source());
567
567
  }
568
568
  catch (error) {
569
- throw new Error("Uncaught error on anyMatch.");
569
+ throw error;
570
570
  }
571
571
  }
572
572
  throw new TypeError("Predicate must be a function.");
@@ -595,7 +595,7 @@ export class AsynchronousCollectable {
595
595
  }
596
596
  }
597
597
  catch (error) {
598
- throw new Error("Uncaught error on collect.");
598
+ throw error;
599
599
  }
600
600
  throw new TypeError("Invalid arguments.");
601
601
  }
@@ -608,7 +608,7 @@ export class AsynchronousCollectable {
608
608
  await useAsynchronousError().collect(this.source());
609
609
  }
610
610
  catch (error) {
611
- throw new Error("Uncaught error on error.");
611
+ throw error;
612
612
  }
613
613
  }
614
614
  else if (isFunction(argument1) && invalidate(argument2) && invalidate(argument3)) {
@@ -617,7 +617,7 @@ export class AsynchronousCollectable {
617
617
  await useAsynchronousError(accumulator).collect(this.source());
618
618
  }
619
619
  catch (error) {
620
- throw new Error("Uncaught error on error.");
620
+ throw error;
621
621
  }
622
622
  }
623
623
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -628,7 +628,7 @@ export class AsynchronousCollectable {
628
628
  await useAsynchronousError(prefix, accumulator, suffix).collect(this.source());
629
629
  }
630
630
  catch (error) {
631
- throw new Error("Uncaught error on error.");
631
+ throw error;
632
632
  }
633
633
  }
634
634
  else {
@@ -643,7 +643,7 @@ export class AsynchronousCollectable {
643
643
  return await useAsynchronousFindAny().collect(this.source());
644
644
  }
645
645
  catch (error) {
646
- throw new Error("Uncaught error on findAny.");
646
+ throw error;
647
647
  }
648
648
  }
649
649
  async findAt(index) {
@@ -652,7 +652,7 @@ export class AsynchronousCollectable {
652
652
  return await useAsynchronousFindAt(index).collect(this.source());
653
653
  }
654
654
  catch (error) {
655
- throw new Error("Uncaught error on findAt.");
655
+ throw error;
656
656
  }
657
657
  }
658
658
  else if (isNumber(index)) {
@@ -660,17 +660,36 @@ export class AsynchronousCollectable {
660
660
  return await useAsynchronousFindAt(index).collect(this.source());
661
661
  }
662
662
  catch (error) {
663
- throw new Error("Uncaught error on findAt.");
663
+ throw error;
664
664
  }
665
665
  }
666
666
  throw new TypeError("Index must be a bigint.");
667
667
  }
668
+ async findNegativeAt(index) {
669
+ if (isBigInt(index)) {
670
+ try {
671
+ return await useAsynchronousFindNegativeAt(index).collect(this.source());
672
+ }
673
+ catch (error) {
674
+ throw error;
675
+ }
676
+ }
677
+ else if (isNumber(index)) {
678
+ try {
679
+ return await useAsynchronousFindNegativeAt(index).collect(this.source());
680
+ }
681
+ catch (error) {
682
+ throw error;
683
+ }
684
+ }
685
+ throw new TypeError("Index must be a bigint or a number.");
686
+ }
668
687
  async findFirst() {
669
688
  try {
670
689
  return await useAsynchronousFindFirst().collect(this.source());
671
690
  }
672
691
  catch (error) {
673
- throw new Error("Uncaught error on findFirst.");
692
+ throw error;
674
693
  }
675
694
  }
676
695
  async findLast() {
@@ -678,7 +697,7 @@ export class AsynchronousCollectable {
678
697
  return await useAsynchronousFindLast().collect(this.source());
679
698
  }
680
699
  catch (error) {
681
- throw new Error("Uncaught error on findLast.");
700
+ throw error;
682
701
  }
683
702
  }
684
703
  async findMaximum(argument1) {
@@ -687,7 +706,7 @@ export class AsynchronousCollectable {
687
706
  return await useAsynchronousFindMaximum(comparator).collect(this.source());
688
707
  }
689
708
  catch (error) {
690
- throw new Error("Uncaught error on findMaximum.");
709
+ throw error;
691
710
  }
692
711
  }
693
712
  async findMinimum(argument1) {
@@ -696,7 +715,7 @@ export class AsynchronousCollectable {
696
715
  return await useAsynchronousFindMinimum(comparator).collect(this.source());
697
716
  }
698
717
  catch (error) {
699
- throw new Error("Uncaught error on findMinimum.");
718
+ throw error;
700
719
  }
701
720
  }
702
721
  async forEach(action) {
@@ -705,7 +724,7 @@ export class AsynchronousCollectable {
705
724
  await useAsynchronousForEach(action).collect(this);
706
725
  }
707
726
  catch (error) {
708
- throw new Error("Uncaught error on forEach.");
727
+ throw error;
709
728
  }
710
729
  }
711
730
  else {
@@ -718,7 +737,7 @@ export class AsynchronousCollectable {
718
737
  return await useAsynchronousGroup(classifier).collect(this.source());
719
738
  }
720
739
  catch (error) {
721
- throw new Error("Uncaught error on group.");
740
+ throw error;
722
741
  }
723
742
  }
724
743
  throw new TypeError("Classifier must be a function.");
@@ -729,7 +748,7 @@ export class AsynchronousCollectable {
729
748
  return await useAsynchronousGroupBy(keyExtractor, valueExtractor).collect(this.source());
730
749
  }
731
750
  catch (error) {
732
- throw new Error("Uncaught error on groupBy.");
751
+ throw error;
733
752
  }
734
753
  }
735
754
  throw new TypeError("Key and value extractors must be functions.");
@@ -740,7 +759,7 @@ export class AsynchronousCollectable {
740
759
  return await useAsynchronousJoin().collect(this.source());
741
760
  }
742
761
  catch (error) {
743
- throw new Error("Uncaught error on join.");
762
+ throw error;
744
763
  }
745
764
  }
746
765
  else if (isString(argument1) && invalidate(argument2) && invalidate(argument3)) {
@@ -749,7 +768,7 @@ export class AsynchronousCollectable {
749
768
  return await useAsynchronousJoin(delimiter).collect(this.source());
750
769
  }
751
770
  catch (error) {
752
- throw new Error("Uncaught error on join.");
771
+ throw error;
753
772
  }
754
773
  }
755
774
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -760,7 +779,7 @@ export class AsynchronousCollectable {
760
779
  return await useAsynchronousJoin(prefix, accumulator, suffix).collect(this.source());
761
780
  }
762
781
  catch (error) {
763
- throw new Error("Uncaught error on join.");
782
+ throw error;
764
783
  }
765
784
  }
766
785
  else if (isString(argument1) && isString(argument2) && isString(argument3)) {
@@ -771,7 +790,7 @@ export class AsynchronousCollectable {
771
790
  return await useAsynchronousJoin(prefix, delimiter, suffix).collect(this.source());
772
791
  }
773
792
  catch (error) {
774
- throw new Error("Uncaught error on join.");
793
+ throw error;
775
794
  }
776
795
  }
777
796
  throw new TypeError("Invalid arguments.");
@@ -783,7 +802,7 @@ export class AsynchronousCollectable {
783
802
  await useAsynchronousLog(accumulator).collect(this.source());
784
803
  }
785
804
  catch (error) {
786
- throw new Error("Uncaught error on log.");
805
+ throw error;
787
806
  }
788
807
  }
789
808
  else if (isString(argument1) && isFunction(argument2) && isString(argument3)) {
@@ -794,7 +813,7 @@ export class AsynchronousCollectable {
794
813
  await useAsynchronousLog(prefix, accumulator, suffix).collect(this.source());
795
814
  }
796
815
  catch (error) {
797
- throw new Error("Uncaught error on log.");
816
+ throw error;
798
817
  }
799
818
  }
800
819
  else {
@@ -802,7 +821,7 @@ export class AsynchronousCollectable {
802
821
  useAsynchronousLog().collect(this.source());
803
822
  }
804
823
  catch (error) {
805
- throw new Error("Uncaught error on log.");
824
+ throw error;
806
825
  }
807
826
  }
808
827
  }
@@ -812,7 +831,7 @@ export class AsynchronousCollectable {
812
831
  return await useAsynchronousNoneMatch(predicate).collect(this.source());
813
832
  }
814
833
  catch (error) {
815
- throw new Error("Uncaught error on nonMatch.");
834
+ throw error;
816
835
  }
817
836
  }
818
837
  throw new TypeError("Predicate must be a function.");
@@ -823,7 +842,7 @@ export class AsynchronousCollectable {
823
842
  return await useAsynchronousPartition(count).collect(this.source());
824
843
  }
825
844
  catch (error) {
826
- throw new Error("Uncaught error on partition.");
845
+ throw error;
827
846
  }
828
847
  }
829
848
  throw new TypeError("Count must be a BigInt.");
@@ -835,7 +854,7 @@ export class AsynchronousCollectable {
835
854
  return await collector.collect(this.source());
836
855
  }
837
856
  catch (error) {
838
- throw new Error("Uncaught error on partitionBy.");
857
+ throw error;
839
858
  }
840
859
  }
841
860
  throw new TypeError("Classifier must be a function.");
@@ -847,7 +866,7 @@ export class AsynchronousCollectable {
847
866
  return await useAsynchronousReduce(accumulator).collect(this.source());
848
867
  }
849
868
  catch (error) {
850
- throw new Error("Uncaught error on reduce.");
869
+ throw error;
851
870
  }
852
871
  }
853
872
  else if (validate(argument1) && isFunction(argument2) && invalidate(argument3)) {
@@ -857,7 +876,7 @@ export class AsynchronousCollectable {
857
876
  return await useAsynchronousReduce(identity, accumulator).collect(this.source());
858
877
  }
859
878
  catch (error) {
860
- throw new Error("Uncaught error on reduce.");
879
+ throw error;
861
880
  }
862
881
  }
863
882
  else if (validate(argument1) && isFunction(argument2) && isFunction(argument3)) {
@@ -868,7 +887,7 @@ export class AsynchronousCollectable {
868
887
  return await useAsynchronousReduce(identity, accumulator, finisher).collect(this.source());
869
888
  }
870
889
  catch (error) {
871
- throw new Error("Uncaught error on reduce.");
890
+ throw error;
872
891
  }
873
892
  }
874
893
  else {
@@ -882,7 +901,7 @@ export class AsynchronousCollectable {
882
901
  return new AsynchronousSemantic(source);
883
902
  }
884
903
  catch (error) {
885
- throw new Error("Uncaught error on semantic.");
904
+ throw error;
886
905
  }
887
906
  }
888
907
  else {
@@ -894,7 +913,7 @@ export class AsynchronousCollectable {
894
913
  return useAsynchronousToArray().collect(this.source());
895
914
  }
896
915
  catch (error) {
897
- throw new Error("Uncaught error on toArray.");
916
+ throw error;
898
917
  }
899
918
  }
900
919
  async toMap(keyExtractor, valueExtractor = (element) => element) {
@@ -902,7 +921,7 @@ export class AsynchronousCollectable {
902
921
  return await useAsynchronousToMap(keyExtractor, valueExtractor).collect(this.source());
903
922
  }
904
923
  catch (error) {
905
- throw new Error("Uncaught error on toMap.");
924
+ throw error;
906
925
  }
907
926
  }
908
927
  async toSet() {
@@ -910,7 +929,7 @@ export class AsynchronousCollectable {
910
929
  return await useAsynchronousToSet().collect(this.source());
911
930
  }
912
931
  catch (error) {
913
- throw new Error("Uncaught error on toSet.");
932
+ throw error;
914
933
  }
915
934
  }
916
935
  async write(argument1, argument2) {
@@ -926,7 +945,7 @@ export class AsynchronousCollectable {
926
945
  }
927
946
  }
928
947
  catch (error) {
929
- throw new Error("Uncaught error on write.");
948
+ throw error;
930
949
  }
931
950
  }
932
951
  throw new TypeError("Invalid arguments.");
@@ -993,7 +1012,7 @@ export class AsynchronousOrderedCollectable extends AsynchronousCollectable {
993
1012
  });
994
1013
  }
995
1014
  catch (error) {
996
- throw new Error("Uncaught error on creating buffer.");
1015
+ throw error;
997
1016
  }
998
1017
  }
999
1018
  else {
@@ -1417,7 +1436,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1417
1436
  return await useAsynchronousBigIntAverage(mapper).collect(this.source());
1418
1437
  }
1419
1438
  catch (error) {
1420
- throw new Error("Uncaught error on average.");
1439
+ throw error;
1421
1440
  }
1422
1441
  }
1423
1442
  async range(argument1) {
@@ -1432,7 +1451,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1432
1451
  return difference < 0 ? -difference : difference;
1433
1452
  }
1434
1453
  catch (error) {
1435
- throw new Error("Uncaught error on range.");
1454
+ throw error;
1436
1455
  }
1437
1456
  }
1438
1457
  async variance(argument1) {
@@ -1444,7 +1463,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1444
1463
  return await useAsynchronousBigIntVariance(mapper).collect(this.source());
1445
1464
  }
1446
1465
  catch (error) {
1447
- throw new Error("Uncaught error on variance.");
1466
+ throw error;
1448
1467
  }
1449
1468
  }
1450
1469
  async standardDeviation(argument1) {
@@ -1454,7 +1473,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1454
1473
  return BigInt(Math.sqrt(Number(variance)));
1455
1474
  }
1456
1475
  catch (error) {
1457
- throw new Error("Uncaught error on standardDeviation.");
1476
+ throw error;
1458
1477
  }
1459
1478
  }
1460
1479
  async mean(argument1) {
@@ -1466,7 +1485,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1466
1485
  return await useAsynchronousBigIntAverage(mapper).collect(this.source());
1467
1486
  }
1468
1487
  catch (error) {
1469
- throw new Error("Uncaught error on mean.");
1488
+ throw error;
1470
1489
  }
1471
1490
  }
1472
1491
  async median(argument1) {
@@ -1478,7 +1497,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1478
1497
  return useAsynchronousBigIntMedian(mapper).collect(this.source());
1479
1498
  }
1480
1499
  catch (error) {
1481
- throw new Error("Uncaught error on median.");
1500
+ throw error;
1482
1501
  }
1483
1502
  }
1484
1503
  async mode(argument1) {
@@ -1490,7 +1509,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1490
1509
  return useAsynchronousBigIntMode(mapper).collect(this.source());
1491
1510
  }
1492
1511
  catch (error) {
1493
- throw new Error("Uncaught error on mode.");
1512
+ throw error;
1494
1513
  }
1495
1514
  }
1496
1515
  async summate(argument1) {
@@ -1502,7 +1521,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1502
1521
  return await useAsynchronousBigIntSummate(mapper).collect(this.source());
1503
1522
  }
1504
1523
  catch (error) {
1505
- throw new Error("Uncaught error on summate.");
1524
+ throw error;
1506
1525
  }
1507
1526
  }
1508
1527
  async quantile(quantile, argument1) {
@@ -1523,7 +1542,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1523
1542
  return value;
1524
1543
  }
1525
1544
  catch (error) {
1526
- throw new Error("Uncaught error on quantile.");
1545
+ throw error;
1527
1546
  }
1528
1547
  }
1529
1548
  async interquartileRange(argument1) {
@@ -1537,7 +1556,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1537
1556
  return upper - lower;
1538
1557
  }
1539
1558
  catch (error) {
1540
- throw new Error("Uncaught error on interquartileRange.");
1559
+ throw error;
1541
1560
  }
1542
1561
  }
1543
1562
  async skewness(argument1) {
@@ -1560,7 +1579,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1560
1579
  return summate / BigInt(data.length);
1561
1580
  }
1562
1581
  catch (error) {
1563
- throw new Error("Uncaught error on skewness.");
1582
+ throw error;
1564
1583
  }
1565
1584
  }
1566
1585
  async kurtosis(argument1) {
@@ -1584,7 +1603,7 @@ export class AsynchronousBigIntStatistics extends AsynchronousStatistics {
1584
1603
  return summate / BigInt(count * count) - 3n;
1585
1604
  }
1586
1605
  catch (error) {
1587
- throw new Error("Uncaught error on kurtosis.");
1606
+ throw error;
1588
1607
  }
1589
1608
  }
1590
1609
  }
@@ -1619,7 +1638,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1619
1638
  return useAsynchronousNumericAverage().collect(this.source());
1620
1639
  }
1621
1640
  catch (error) {
1622
- throw new Error("Uncaught error on average.");
1641
+ throw error;
1623
1642
  }
1624
1643
  }
1625
1644
  async range(argument1) {
@@ -1636,7 +1655,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1636
1655
  return mapper(maximum) - mapper(minimum);
1637
1656
  }
1638
1657
  catch (error) {
1639
- throw new Error("Uncaught error on range.");
1658
+ throw error;
1640
1659
  }
1641
1660
  }
1642
1661
  async variance(argument1) {
@@ -1648,7 +1667,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1648
1667
  return await useAsynchronousNumericVariance(mapper).collect(this.source());
1649
1668
  }
1650
1669
  catch (error) {
1651
- throw new Error("Uncaught error on variance.");
1670
+ throw error;
1652
1671
  }
1653
1672
  }
1654
1673
  async standardDeviation(argument1) {
@@ -1657,7 +1676,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1657
1676
  return await useAsynchronousNumericStandardDeviation(mapper).collect(this.source());
1658
1677
  }
1659
1678
  catch (error) {
1660
- throw new Error("Uncaught error on standardDeviation.");
1679
+ throw error;
1661
1680
  }
1662
1681
  }
1663
1682
  async mean(argument1) {
@@ -1669,7 +1688,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1669
1688
  return useAsynchronousNumericAverage(mapper).collect(this.source());
1670
1689
  }
1671
1690
  catch (error) {
1672
- throw new Error("Uncaught error on mean.");
1691
+ throw error;
1673
1692
  }
1674
1693
  }
1675
1694
  async median(argument1) {
@@ -1681,7 +1700,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1681
1700
  return await useAsynchronousNumericMedian(mapper).collect(this.source());
1682
1701
  }
1683
1702
  catch (error) {
1684
- throw new Error("Uncaught error on median.");
1703
+ throw error;
1685
1704
  }
1686
1705
  }
1687
1706
  async mode(argument1) {
@@ -1693,7 +1712,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1693
1712
  return await useAsynchronousNumericMode(mapper).collect(this.source());
1694
1713
  }
1695
1714
  catch (error) {
1696
- throw new Error("Uncaught error on mode.");
1715
+ throw error;
1697
1716
  }
1698
1717
  }
1699
1718
  async summate(argument1) {
@@ -1705,7 +1724,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1705
1724
  return useAsynchronousNumericSummate(mapper).collect(this.source());
1706
1725
  }
1707
1726
  catch (error) {
1708
- throw new Error("Uncaught error on summate.");
1727
+ throw error;
1709
1728
  }
1710
1729
  }
1711
1730
  async quantile(quantile, argument1) {
@@ -1726,7 +1745,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1726
1745
  return value;
1727
1746
  }
1728
1747
  catch (error) {
1729
- throw new Error("Uncaught error on quantile.");
1748
+ throw error;
1730
1749
  }
1731
1750
  }
1732
1751
  async interquartileRange(argument1) {
@@ -1740,7 +1759,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1740
1759
  return upper - lower;
1741
1760
  }
1742
1761
  catch (error) {
1743
- throw new Error("Uncaught error on interquartileRange.");
1762
+ throw error;
1744
1763
  }
1745
1764
  }
1746
1765
  async skewness(argument1) {
@@ -1763,7 +1782,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1763
1782
  return summate / data.length;
1764
1783
  }
1765
1784
  catch (error) {
1766
- throw new Error("Uncaught error on skewness.");
1785
+ throw error;
1767
1786
  }
1768
1787
  }
1769
1788
  async kurtosis(argument1) {
@@ -1786,7 +1805,7 @@ export class AsynchronousNumericStatistics extends AsynchronousStatistics {
1786
1805
  return summate / (data.length * data.length) - 3;
1787
1806
  }
1788
1807
  catch (error) {
1789
- throw new Error("Uncaught error on kurtosis.");
1808
+ throw error;
1790
1809
  }
1791
1810
  }
1792
1811
  }
@@ -1844,7 +1863,7 @@ export class AsynchronousWindowCollectable extends AsynchronousOrderedCollectabl
1844
1863
  resolve();
1845
1864
  }
1846
1865
  catch (error) {
1847
- throw new Error("Uncaught error on slide.");
1866
+ throw error;
1848
1867
  }
1849
1868
  });
1850
1869
  });
@@ -1857,7 +1876,7 @@ export class AsynchronousWindowCollectable extends AsynchronousOrderedCollectabl
1857
1876
  return this.slide(size, size);
1858
1877
  }
1859
1878
  catch (error) {
1860
- throw new Error("Uncaught error on tumble.");
1879
+ throw error;
1861
1880
  }
1862
1881
  }
1863
1882
  throw new RangeError("Invalid arguments.");
@@ -59,10 +59,15 @@ interface UseSynchronousError {
59
59
  }
60
60
  export declare let useSynchronousError: UseSynchronousError;
61
61
  interface UseSynchronousFindAt {
62
+ <E>(index: number): SynchronousCollector<E, Optional<E>, Optional<E>>;
63
+ <E>(index: bigint): SynchronousCollector<E, Optional<E>, Optional<E>>;
64
+ }
65
+ export declare let useSynchronousFindAt: UseSynchronousFindAt;
66
+ interface UseSynchronousFindNegativeAt {
62
67
  <E>(index: number): SynchronousCollector<E, Array<E>, Optional<E>>;
63
68
  <E>(index: bigint): SynchronousCollector<E, Array<E>, Optional<E>>;
64
69
  }
65
- export declare let useSynchronousFindAt: UseSynchronousFindAt;
70
+ export declare let useSynchronousFindNegativeAt: UseSynchronousFindNegativeAt;
66
71
  export declare let useSynchronousFindFirst: <E>() => SynchronousCollector<E, Optional<E>, Optional<E>>;
67
72
  export declare let useSynchronousFindAny: <E>() => SynchronousCollector<E, Optional<E>, Optional<E>>;
68
73
  export declare let useSynchronousFindLast: <E>() => SynchronousCollector<E, Optional<E>, Optional<E>>;
@@ -220,26 +220,30 @@ export let useSynchronousError = (argument1, argument2, argument3) => {
220
220
  export let useSynchronousFindAt = (index) => {
221
221
  let target = useToBigInt(index);
222
222
  if (target < 0n) {
223
- return SynchronousCollector.full(() => [], (accumulator, element) => {
224
- let accumulated = Array.isArray(accumulator) ? accumulator : [];
225
- accumulated.push(element);
226
- return accumulated;
227
- }, (result) => {
228
- if (Array.isArray(result) && result.length > 0) {
229
- let index = ((Number(target) % result.length) + result.length) % result.length;
230
- return Optional.of(result[index]);
231
- }
232
- return Optional.empty();
233
- });
223
+ throw new Error("use \"useSynchronousFindNegativeAt\" for negative index.");
234
224
  }
235
- return SynchronousCollector.shortable(() => [], (_element, _index, accumulator) => BigInt(accumulator.length) - 1n === target, (accumulator, element) => {
236
- let accumulated = Array.isArray(accumulator) ? accumulator : [];
237
- accumulated.push(element);
238
- return accumulated;
239
- }, (result) => {
240
- let index = ((Number(target) % result.length) + result.length) % result.length;
241
- if (Array.isArray(result) && result.length > 0) {
242
- return Optional.of(result[index]);
225
+ return SynchronousCollector.shortable(Optional.empty, (_element, _index, accumulator) => accumulator.isPresent(), (accumulator, element, index) => {
226
+ if (index === target) {
227
+ return Optional.of(element);
228
+ }
229
+ return accumulator;
230
+ }, (accumulator) => accumulator);
231
+ };
232
+ ;
233
+ export let useSynchronousFindNegativeAt = (index) => {
234
+ let target = useToBigInt(index);
235
+ if (target > -1n) {
236
+ throw new Error("use \"useSynchronousFindAt\" for none-negative index.");
237
+ }
238
+ return SynchronousCollector.full(() => [], (accumulator, element) => {
239
+ accumulator.push(element);
240
+ return accumulator;
241
+ }, (accumulator) => {
242
+ if (accumulator.length > 0) {
243
+ let count = BigInt(accumulator.length);
244
+ let limit = ((target % count) + count) % count;
245
+ let element = accumulator.at(Number(limit));
246
+ return Optional.of(element);
243
247
  }
244
248
  return Optional.empty();
245
249
  });
@@ -81,6 +81,8 @@ export declare abstract class SynchronousCollectable<E> implements Iterable<E> {
81
81
  findAny(): Optional<E>;
82
82
  findAt(index: number): Optional<E>;
83
83
  findAt(index: bigint): Optional<E>;
84
+ findNegativeAt(index: number): Optional<E>;
85
+ findNegativeAt(index: bigint): Optional<E>;
84
86
  findFirst(): Optional<E>;
85
87
  findLast(): Optional<E>;
86
88
  findMaximum(): Optional<E>;
@@ -1,4 +1,4 @@
1
- import { useSynchronousAnyMatch, useSynchronousAllMatch, useSynchronousCollect, useSynchronousCount, useSynchronousError, useSynchronousFindAny, useSynchronousFindAt, useSynchronousFindFirst, useSynchronousFindLast, useSynchronousFindMaximum, useSynchronousFindMinimum, useSynchronousForEach, useSynchronousGroup, useSynchronousGroupBy, useSynchronousJoin, useSynchronousLog, useSynchronousNoneMatch, useSynchronousPartition, useSynchronousPartitionBy, useSynchronousReduce, useSynchronousToArray, useSynchronousToMap, useSynchronousToSet, useSynchronousWrite, useSynchronousFrequency, useSynchronousBigIntAverage, useSynchronousBigIntMedian, useSynchronousBigIntMode, useSynchronousBigIntSummate, useSynchronousBigIntVariance, useSynchronousNumericAverage, useSynchronousNumericMedian, useSynchronousNumericMode, useSynchronousNumericStandardDeviation, useSynchronousNumericSummate, useSynchronousNumericVariance } from "./collector";
1
+ import { useSynchronousAnyMatch, useSynchronousAllMatch, useSynchronousCollect, useSynchronousCount, useSynchronousError, useSynchronousFindAny, useSynchronousFindAt, useSynchronousFindFirst, useSynchronousFindLast, useSynchronousFindMaximum, useSynchronousFindMinimum, useSynchronousForEach, useSynchronousGroup, useSynchronousGroupBy, useSynchronousJoin, useSynchronousLog, useSynchronousNoneMatch, useSynchronousPartition, useSynchronousPartitionBy, useSynchronousReduce, useSynchronousToArray, useSynchronousToMap, useSynchronousToSet, useSynchronousWrite, useSynchronousFrequency, useSynchronousBigIntAverage, useSynchronousBigIntMedian, useSynchronousBigIntMode, useSynchronousBigIntSummate, useSynchronousBigIntVariance, useSynchronousNumericAverage, useSynchronousNumericMedian, useSynchronousNumericMode, useSynchronousNumericStandardDeviation, useSynchronousNumericSummate, useSynchronousNumericVariance, useSynchronousFindNegativeAt } from "./collector";
2
2
  import { isFunction, isSynchronousSemantic, isIterable, isNumber, isBigInt, isObject, isString, isSynchronousCollectable, isSynchronousCollector } from "../guard";
3
3
  import { useHash } from "../hash";
4
4
  import { useCompare, useToBigInt, useToNumber } from "../hook";
@@ -99,7 +99,6 @@ export class SynchronousSemantic {
99
99
  this.generator((element, index) => {
100
100
  if (count === -1n) {
101
101
  if (!predicate(element, index)) {
102
- accept(element, count);
103
102
  count++;
104
103
  }
105
104
  }
@@ -270,14 +269,9 @@ export class SynchronousSemantic {
270
269
  if (isFunction(redirector)) {
271
270
  return new SynchronousSemantic((accept, interrupt) => {
272
271
  try {
273
- let stop = false;
274
272
  this.generator((element, index) => {
275
- let redirected = redirector(element, index);
276
- stop = stop || interrupt(element, redirected);
277
- accept(element, redirected);
278
- }, () => {
279
- return stop;
280
- });
273
+ accept(element, redirector(element, index));
274
+ }, interrupt);
281
275
  }
282
276
  catch (error) {
283
277
  throw error;
@@ -289,14 +283,9 @@ export class SynchronousSemantic {
289
283
  reverse() {
290
284
  return new SynchronousSemantic((accept, interrupt) => {
291
285
  try {
292
- let stop = false;
293
286
  this.generator((element, index) => {
294
- let redirected = -index;
295
- stop = stop || interrupt(element, redirected);
296
- accept(element, redirected);
297
- }, () => {
298
- return stop;
299
- });
287
+ accept(element, -index);
288
+ }, interrupt);
300
289
  }
301
290
  catch (error) {
302
291
  throw error;
@@ -307,14 +296,9 @@ export class SynchronousSemantic {
307
296
  if (isFunction(mapper)) {
308
297
  return new SynchronousSemantic((accept, interrupt) => {
309
298
  try {
310
- let stop = false;
311
299
  this.generator((element, index) => {
312
- let redirected = mapper(element, index);
313
- stop = stop || interrupt(element, redirected);
314
- accept(element, redirected);
315
- }, () => {
316
- return stop;
317
- });
300
+ accept(element, mapper(element, index));
301
+ }, interrupt);
318
302
  }
319
303
  catch (error) {
320
304
  throw error;
@@ -405,7 +389,7 @@ export class SynchronousSemantic {
405
389
  try {
406
390
  let stop = false;
407
391
  this.generator((element, index) => {
408
- if (predicate(element, index) && (!stop)) {
392
+ if (predicate(element, index) && !stop) {
409
393
  accept(element, index);
410
394
  }
411
395
  else {
@@ -642,6 +626,25 @@ export class SynchronousCollectable {
642
626
  }
643
627
  throw new TypeError("Index must be a bigint.");
644
628
  }
629
+ findNegativeAt(index) {
630
+ if (isBigInt(index)) {
631
+ try {
632
+ return useSynchronousFindNegativeAt(index).collect(this.source());
633
+ }
634
+ catch (error) {
635
+ throw error;
636
+ }
637
+ }
638
+ else if (isNumber(index)) {
639
+ try {
640
+ return useSynchronousFindNegativeAt(index).collect(this.source());
641
+ }
642
+ catch (error) {
643
+ throw error;
644
+ }
645
+ }
646
+ throw new TypeError("Index must be a bigint.");
647
+ }
645
648
  findFirst() {
646
649
  try {
647
650
  return useSynchronousFindFirst().collect(this.source());
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "https://github.com/eloyhere"
7
7
  },
8
8
  "description": "A modern type-safe stream processing library inspired by JavaScript Generator, Java Stream, and MySQL Index. Supports lazy evaluation, async streams, statistics, and IO-like operations.",
9
- "version": "0.8.0",
9
+ "version": "1.0.0",
10
10
  "type": "module",
11
11
  "readme": "readme.md",
12
12
  "main": "dist/index.js",
@@ -55,4 +55,4 @@
55
55
  "build": "tsc",
56
56
  "prepublishOnly": "npm run build"
57
57
  }
58
- }
58
+ }