retuple 1.0.0-next.16 → 1.0.0-next.17

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/index.cjs CHANGED
@@ -740,22 +740,43 @@ class ResultOk extends RetupleArray {
740
740
  $or() {
741
741
  return this;
742
742
  }
743
+ $orAsync() {
744
+ return this.$async();
745
+ }
743
746
  $orElse() {
744
747
  return this;
745
748
  }
749
+ $orElseAsync() {
750
+ return this.$async();
751
+ }
746
752
  $orSafe() {
747
753
  return this;
748
754
  }
755
+ $orSafeAsync() {
756
+ return this.$async();
757
+ }
758
+ $orSafePromise() {
759
+ return this.$async();
760
+ }
749
761
  $and(and) {
750
762
  return asResult(and);
751
763
  }
764
+ $andAsync(and) {
765
+ return this.$async().$and(and);
766
+ }
752
767
  $andThen(f) {
753
768
  return asResult(f(this[1]));
754
769
  }
770
+ $andThenAsync(f) {
771
+ return this.$async().$andThen(f);
772
+ }
755
773
  $andThrough(f) {
756
774
  const res = asResult(f(this[1]));
757
775
  return res instanceof ResultErr ? res : this;
758
776
  }
777
+ $andThroughAsync(f) {
778
+ return this.$async().$andThrough(f);
779
+ }
759
780
  $andSafe(f, mapError = ensureError) {
760
781
  try {
761
782
  return Ok(f(this[1]));
@@ -764,6 +785,12 @@ class ResultOk extends RetupleArray {
764
785
  return Err(mapError(err));
765
786
  }
766
787
  }
788
+ $andSafeAsync(f, mapError = ensureError) {
789
+ return this.$async().$andSafe(f, mapError);
790
+ }
791
+ $andSafePromise(promise, mapError = ensureError) {
792
+ return this.$async().$andSafePromise(promise, mapError);
793
+ }
767
794
  $peek(f) {
768
795
  f(this);
769
796
  return this;
@@ -856,9 +883,15 @@ class ResultErr extends RetupleArray {
856
883
  $or(or) {
857
884
  return asResult(or);
858
885
  }
886
+ $orAsync(or) {
887
+ return this.$async().$or(or);
888
+ }
859
889
  $orElse(f) {
860
890
  return asResult(f(this[0]));
861
891
  }
892
+ $orElseAsync(f) {
893
+ return this.$async().$orElse(f);
894
+ }
862
895
  $orSafe(f, mapError = ensureError) {
863
896
  try {
864
897
  return Ok(f(this[0]));
@@ -867,18 +900,39 @@ class ResultErr extends RetupleArray {
867
900
  return Err(mapError(err));
868
901
  }
869
902
  }
903
+ $orSafeAsync(f, mapError = ensureError) {
904
+ return this.$async().$orSafe(f, mapError);
905
+ }
906
+ $orSafePromise(promise, mapError = ensureError) {
907
+ return this.$async().$orSafePromise(promise, mapError);
908
+ }
870
909
  $and() {
871
910
  return this;
872
911
  }
912
+ $andAsync() {
913
+ return this.$async();
914
+ }
873
915
  $andThen() {
874
916
  return this;
875
917
  }
918
+ $andThenAsync() {
919
+ return this.$async();
920
+ }
876
921
  $andThrough() {
877
922
  return this;
878
923
  }
924
+ $andThroughAsync() {
925
+ return this.$async();
926
+ }
879
927
  $andSafe() {
880
928
  return this;
881
929
  }
930
+ $andSafeAsync() {
931
+ return this.$async();
932
+ }
933
+ $andSafePromise() {
934
+ return this.$async();
935
+ }
882
936
  $peek(f) {
883
937
  f(this);
884
938
  return this;
package/dist/index.d.cts CHANGED
@@ -1375,6 +1375,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1375
1375
  * ```
1376
1376
  */
1377
1377
  $or<U = T, F = E>(this: Result<T, E>, or: ResultLike<U, F>): Result<T | U, F>;
1378
+ /**
1379
+ * Shorthand for `result.$async().$or(...)`
1380
+ */
1381
+ $orAsync<U = T, F = E>(this: Result<T, E>, or: ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1378
1382
  /**
1379
1383
  * Returns the result returned by the or function, when this result is `Err`.
1380
1384
  *
@@ -1411,6 +1415,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1411
1415
  * ```
1412
1416
  */
1413
1417
  $orElse<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLike<U, F>): Result<T | U, F>;
1418
+ /**
1419
+ * Shorthand for `result.$async().$orElse(...)`
1420
+ */
1421
+ $orElseAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1414
1422
  /**
1415
1423
  * Returns a {@link Result} based on the outcome of the safe function when
1416
1424
  * this result is `Err`.
@@ -1422,6 +1430,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1422
1430
  */
1423
1431
  $orSafe<U = T>(this: Result<T, E>, f: (err: E) => U): Result<T | U, Error>;
1424
1432
  $orSafe<U = T, F = E>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, F>;
1433
+ /**
1434
+ * Shorthand for `result.$async().$orSafe(...)`
1435
+ */
1436
+ $orSafeAsync<U = T>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>): ResultAsync<T | U, Error>;
1437
+ $orSafeAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1438
+ /**
1439
+ * Shorthand for `result.$async().$orSafePromise(...)`
1440
+ */
1441
+ $orSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<T | U, Error>;
1442
+ $orSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1425
1443
  /**
1426
1444
  * Returns the and result, when this result is `Ok`.
1427
1445
  *
@@ -1458,6 +1476,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1458
1476
  * ```
1459
1477
  */
1460
1478
  $and<U = T, F = E>(this: Result<T, E>, and: ResultLike<U, F>): Result<U, E | F>;
1479
+ /**
1480
+ * Shorthand for `result.$async().$and(...)`
1481
+ */
1482
+ $andAsync<U = T, F = E>(this: Result<T, E>, and: ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1461
1483
  /**
1462
1484
  * Returns the and result, when this result is `Ok`.
1463
1485
  *
@@ -1494,6 +1516,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1494
1516
  * ```
1495
1517
  */
1496
1518
  $andThen<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLike<U, F>): Result<U, E | F>;
1519
+ /**
1520
+ * Shorthand for `result.$async().$andThen(...)`
1521
+ */
1522
+ $andThenAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1497
1523
  /**
1498
1524
  * Calls the through function when this result is `Ok` and returns:
1499
1525
  *
@@ -1534,6 +1560,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1534
1560
  * ```
1535
1561
  */
1536
1562
  $andThrough<F = E>(this: Result<T, E>, f: (val: T) => ResultLike<any, F>): Result<T, E | F>;
1563
+ /**
1564
+ * Shorthand for `result.$async().$andThrough(...)`
1565
+ */
1566
+ $andThroughAsync<F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<any, F>): ResultAsync<T, E | F>;
1537
1567
  /**
1538
1568
  * Returns a result based on the outcome of the safe function when this
1539
1569
  * result is `Ok`.
@@ -1548,6 +1578,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1548
1578
  */
1549
1579
  $andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<U, E | Error>;
1550
1580
  $andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<U, E | F>;
1581
+ /**
1582
+ * Shorthand for `result.$async().$andSafe(...)`
1583
+ */
1584
+ $andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
1585
+ $andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1586
+ /**
1587
+ * Shorthand for `result.$async().$andSafePromise(...)`
1588
+ */
1589
+ $andSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<U, E | Error>;
1590
+ $andSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1551
1591
  /**
1552
1592
  * Calls the peek function and returns {@link Result} equivalent to this
1553
1593
  * result.
package/dist/index.d.ts CHANGED
@@ -1375,6 +1375,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1375
1375
  * ```
1376
1376
  */
1377
1377
  $or<U = T, F = E>(this: Result<T, E>, or: ResultLike<U, F>): Result<T | U, F>;
1378
+ /**
1379
+ * Shorthand for `result.$async().$or(...)`
1380
+ */
1381
+ $orAsync<U = T, F = E>(this: Result<T, E>, or: ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1378
1382
  /**
1379
1383
  * Returns the result returned by the or function, when this result is `Err`.
1380
1384
  *
@@ -1411,6 +1415,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1411
1415
  * ```
1412
1416
  */
1413
1417
  $orElse<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLike<U, F>): Result<T | U, F>;
1418
+ /**
1419
+ * Shorthand for `result.$async().$orElse(...)`
1420
+ */
1421
+ $orElseAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1414
1422
  /**
1415
1423
  * Returns a {@link Result} based on the outcome of the safe function when
1416
1424
  * this result is `Err`.
@@ -1422,6 +1430,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1422
1430
  */
1423
1431
  $orSafe<U = T>(this: Result<T, E>, f: (err: E) => U): Result<T | U, Error>;
1424
1432
  $orSafe<U = T, F = E>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, F>;
1433
+ /**
1434
+ * Shorthand for `result.$async().$orSafe(...)`
1435
+ */
1436
+ $orSafeAsync<U = T>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>): ResultAsync<T | U, Error>;
1437
+ $orSafeAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1438
+ /**
1439
+ * Shorthand for `result.$async().$orSafePromise(...)`
1440
+ */
1441
+ $orSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<T | U, Error>;
1442
+ $orSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1425
1443
  /**
1426
1444
  * Returns the and result, when this result is `Ok`.
1427
1445
  *
@@ -1458,6 +1476,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1458
1476
  * ```
1459
1477
  */
1460
1478
  $and<U = T, F = E>(this: Result<T, E>, and: ResultLike<U, F>): Result<U, E | F>;
1479
+ /**
1480
+ * Shorthand for `result.$async().$and(...)`
1481
+ */
1482
+ $andAsync<U = T, F = E>(this: Result<T, E>, and: ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1461
1483
  /**
1462
1484
  * Returns the and result, when this result is `Ok`.
1463
1485
  *
@@ -1494,6 +1516,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1494
1516
  * ```
1495
1517
  */
1496
1518
  $andThen<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLike<U, F>): Result<U, E | F>;
1519
+ /**
1520
+ * Shorthand for `result.$async().$andThen(...)`
1521
+ */
1522
+ $andThenAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1497
1523
  /**
1498
1524
  * Calls the through function when this result is `Ok` and returns:
1499
1525
  *
@@ -1534,6 +1560,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1534
1560
  * ```
1535
1561
  */
1536
1562
  $andThrough<F = E>(this: Result<T, E>, f: (val: T) => ResultLike<any, F>): Result<T, E | F>;
1563
+ /**
1564
+ * Shorthand for `result.$async().$andThrough(...)`
1565
+ */
1566
+ $andThroughAsync<F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<any, F>): ResultAsync<T, E | F>;
1537
1567
  /**
1538
1568
  * Returns a result based on the outcome of the safe function when this
1539
1569
  * result is `Ok`.
@@ -1548,6 +1578,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1548
1578
  */
1549
1579
  $andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<U, E | Error>;
1550
1580
  $andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<U, E | F>;
1581
+ /**
1582
+ * Shorthand for `result.$async().$andSafe(...)`
1583
+ */
1584
+ $andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
1585
+ $andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1586
+ /**
1587
+ * Shorthand for `result.$async().$andSafePromise(...)`
1588
+ */
1589
+ $andSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<U, E | Error>;
1590
+ $andSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1551
1591
  /**
1552
1592
  * Calls the peek function and returns {@link Result} equivalent to this
1553
1593
  * result.
package/dist/index.js CHANGED
@@ -728,22 +728,43 @@ class ResultOk extends RetupleArray {
728
728
  $or() {
729
729
  return this;
730
730
  }
731
+ $orAsync() {
732
+ return this.$async();
733
+ }
731
734
  $orElse() {
732
735
  return this;
733
736
  }
737
+ $orElseAsync() {
738
+ return this.$async();
739
+ }
734
740
  $orSafe() {
735
741
  return this;
736
742
  }
743
+ $orSafeAsync() {
744
+ return this.$async();
745
+ }
746
+ $orSafePromise() {
747
+ return this.$async();
748
+ }
737
749
  $and(and) {
738
750
  return asResult(and);
739
751
  }
752
+ $andAsync(and) {
753
+ return this.$async().$and(and);
754
+ }
740
755
  $andThen(f) {
741
756
  return asResult(f(this[1]));
742
757
  }
758
+ $andThenAsync(f) {
759
+ return this.$async().$andThen(f);
760
+ }
743
761
  $andThrough(f) {
744
762
  const res = asResult(f(this[1]));
745
763
  return res instanceof ResultErr ? res : this;
746
764
  }
765
+ $andThroughAsync(f) {
766
+ return this.$async().$andThrough(f);
767
+ }
747
768
  $andSafe(f, mapError = ensureError) {
748
769
  try {
749
770
  return Ok(f(this[1]));
@@ -752,6 +773,12 @@ class ResultOk extends RetupleArray {
752
773
  return Err(mapError(err));
753
774
  }
754
775
  }
776
+ $andSafeAsync(f, mapError = ensureError) {
777
+ return this.$async().$andSafe(f, mapError);
778
+ }
779
+ $andSafePromise(promise, mapError = ensureError) {
780
+ return this.$async().$andSafePromise(promise, mapError);
781
+ }
755
782
  $peek(f) {
756
783
  f(this);
757
784
  return this;
@@ -844,9 +871,15 @@ class ResultErr extends RetupleArray {
844
871
  $or(or) {
845
872
  return asResult(or);
846
873
  }
874
+ $orAsync(or) {
875
+ return this.$async().$or(or);
876
+ }
847
877
  $orElse(f) {
848
878
  return asResult(f(this[0]));
849
879
  }
880
+ $orElseAsync(f) {
881
+ return this.$async().$orElse(f);
882
+ }
850
883
  $orSafe(f, mapError = ensureError) {
851
884
  try {
852
885
  return Ok(f(this[0]));
@@ -855,18 +888,39 @@ class ResultErr extends RetupleArray {
855
888
  return Err(mapError(err));
856
889
  }
857
890
  }
891
+ $orSafeAsync(f, mapError = ensureError) {
892
+ return this.$async().$orSafe(f, mapError);
893
+ }
894
+ $orSafePromise(promise, mapError = ensureError) {
895
+ return this.$async().$orSafePromise(promise, mapError);
896
+ }
858
897
  $and() {
859
898
  return this;
860
899
  }
900
+ $andAsync() {
901
+ return this.$async();
902
+ }
861
903
  $andThen() {
862
904
  return this;
863
905
  }
906
+ $andThenAsync() {
907
+ return this.$async();
908
+ }
864
909
  $andThrough() {
865
910
  return this;
866
911
  }
912
+ $andThroughAsync() {
913
+ return this.$async();
914
+ }
867
915
  $andSafe() {
868
916
  return this;
869
917
  }
918
+ $andSafeAsync() {
919
+ return this.$async();
920
+ }
921
+ $andSafePromise() {
922
+ return this.$async();
923
+ }
870
924
  $peek(f) {
871
925
  f(this);
872
926
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retuple",
3
- "version": "1.0.0-next.16",
3
+ "version": "1.0.0-next.17",
4
4
  "scripts": {
5
5
  "test": "vitest",
6
6
  "lint": "eslint . --ext .ts -c eslint.config.mjs --fix",