retuple 1.0.0-next.16 → 1.0.0-next.18

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
@@ -162,8 +162,6 @@ function $resolve(result) {
162
162
  switch (true) {
163
163
  case result instanceof ResultAsync:
164
164
  return result;
165
- case result instanceof ResultRetry:
166
- return new ResultAsync(result);
167
165
  case result instanceof ResultOk:
168
166
  case result instanceof ResultErr:
169
167
  return new ResultAsync(Promise.resolve(result));
@@ -740,22 +738,43 @@ class ResultOk extends RetupleArray {
740
738
  $or() {
741
739
  return this;
742
740
  }
741
+ $orAsync() {
742
+ return this.$async();
743
+ }
743
744
  $orElse() {
744
745
  return this;
745
746
  }
747
+ $orElseAsync() {
748
+ return this.$async();
749
+ }
746
750
  $orSafe() {
747
751
  return this;
748
752
  }
753
+ $orSafeAsync() {
754
+ return this.$async();
755
+ }
756
+ $orSafePromise() {
757
+ return this.$async();
758
+ }
749
759
  $and(and) {
750
760
  return asResult(and);
751
761
  }
762
+ $andAsync(and) {
763
+ return this.$async().$and(and);
764
+ }
752
765
  $andThen(f) {
753
766
  return asResult(f(this[1]));
754
767
  }
768
+ $andThenAsync(f) {
769
+ return this.$async().$andThen(f);
770
+ }
755
771
  $andThrough(f) {
756
772
  const res = asResult(f(this[1]));
757
773
  return res instanceof ResultErr ? res : this;
758
774
  }
775
+ $andThroughAsync(f) {
776
+ return this.$async().$andThrough(f);
777
+ }
759
778
  $andSafe(f, mapError = ensureError) {
760
779
  try {
761
780
  return Ok(f(this[1]));
@@ -764,6 +783,12 @@ class ResultOk extends RetupleArray {
764
783
  return Err(mapError(err));
765
784
  }
766
785
  }
786
+ $andSafeAsync(f, mapError = ensureError) {
787
+ return this.$async().$andSafe(f, mapError);
788
+ }
789
+ $andSafePromise(promise, mapError = ensureError) {
790
+ return this.$async().$andSafePromise(promise, mapError);
791
+ }
767
792
  $peek(f) {
768
793
  f(this);
769
794
  return this;
@@ -856,9 +881,15 @@ class ResultErr extends RetupleArray {
856
881
  $or(or) {
857
882
  return asResult(or);
858
883
  }
884
+ $orAsync(or) {
885
+ return this.$async().$or(or);
886
+ }
859
887
  $orElse(f) {
860
888
  return asResult(f(this[0]));
861
889
  }
890
+ $orElseAsync(f) {
891
+ return this.$async().$orElse(f);
892
+ }
862
893
  $orSafe(f, mapError = ensureError) {
863
894
  try {
864
895
  return Ok(f(this[0]));
@@ -867,18 +898,39 @@ class ResultErr extends RetupleArray {
867
898
  return Err(mapError(err));
868
899
  }
869
900
  }
901
+ $orSafeAsync(f, mapError = ensureError) {
902
+ return this.$async().$orSafe(f, mapError);
903
+ }
904
+ $orSafePromise(promise, mapError = ensureError) {
905
+ return this.$async().$orSafePromise(promise, mapError);
906
+ }
870
907
  $and() {
871
908
  return this;
872
909
  }
910
+ $andAsync() {
911
+ return this.$async();
912
+ }
873
913
  $andThen() {
874
914
  return this;
875
915
  }
916
+ $andThenAsync() {
917
+ return this.$async();
918
+ }
876
919
  $andThrough() {
877
920
  return this;
878
921
  }
922
+ $andThroughAsync() {
923
+ return this.$async();
924
+ }
879
925
  $andSafe() {
880
926
  return this;
881
927
  }
928
+ $andSafeAsync() {
929
+ return this.$async();
930
+ }
931
+ $andSafePromise() {
932
+ return this.$async();
933
+ }
882
934
  $peek(f) {
883
935
  f(this);
884
936
  return this;
@@ -1158,7 +1210,7 @@ _ResultAsync_inner = new WeakMap();
1158
1210
  /**
1159
1211
  * ## ResultRetry
1160
1212
  */
1161
- class ResultRetry {
1213
+ class ResultRetry extends ResultAsync {
1162
1214
  static zero() {
1163
1215
  return 0;
1164
1216
  }
@@ -1172,6 +1224,7 @@ class ResultRetry {
1172
1224
  return 0;
1173
1225
  }
1174
1226
  constructor(f) {
1227
+ super(Promise.resolve().then(() => __classPrivateFieldGet(this, _ResultRetry_promise, "f")));
1175
1228
  _ResultRetry_f.set(this, void 0);
1176
1229
  _ResultRetry_promise.set(this, void 0);
1177
1230
  _ResultRetry_times.set(this, 1);
@@ -1184,7 +1237,7 @@ class ResultRetry {
1184
1237
  __classPrivateFieldSet(this, _ResultRetry_promise, this.drain(), "f");
1185
1238
  }
1186
1239
  then(onfulfilled, onrejected) {
1187
- return __classPrivateFieldGet(this, _ResultRetry_promise, "f").then(onfulfilled, onrejected);
1240
+ return super.then(onfulfilled, onrejected);
1188
1241
  }
1189
1242
  /**
1190
1243
  * Sets the maximum number of times the retry function can be executed,
@@ -1254,39 +1307,6 @@ class ResultRetry {
1254
1307
  __classPrivateFieldSet(this, _ResultRetry_handler, f, "f");
1255
1308
  return this;
1256
1309
  }
1257
- /**
1258
- * Returns {@link ResultAsync} which resolves to this retried {@link Result}.
1259
- *
1260
- * @example
1261
- *
1262
- * ```ts
1263
- * const result: Result<string, SomeError> = await Result
1264
- * .$retry(someResultFn)
1265
- * .$times(3)
1266
- * .$delay(100)
1267
- * .$async()
1268
- * .$andThen((message) => `Success: ${message}`)
1269
- * .$mapErr((code) => new SomeError({ code }));
1270
- * ```
1271
- */
1272
- $async() {
1273
- return new ResultAsync(this);
1274
- }
1275
- /**
1276
- * Returns a `Promise` which resolves to this retried {@link Result}.
1277
- *
1278
- * @example
1279
- *
1280
- * ```ts
1281
- * const promise: Promise<Result<string, Error>> = Result
1282
- * .$retry(someResultFn)
1283
- * .$times(3)
1284
- * .$promise();
1285
- * ```
1286
- */
1287
- $promise() {
1288
- return Promise.resolve(this);
1289
- }
1290
1310
  async drain() {
1291
1311
  var _b;
1292
1312
  while (__classPrivateFieldGet(this, _ResultRetry_attempt, "f") < __classPrivateFieldGet(this, _ResultRetry_times, "f")) {
package/dist/index.d.cts CHANGED
@@ -644,7 +644,7 @@ declare class ResultAsync<T, E> {
644
644
  /**
645
645
  * ## ResultRetry
646
646
  */
647
- declare class ResultRetry<T, E> implements PromiseLike<Result<T, E>> {
647
+ declare class ResultRetry<T, E> extends ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
648
648
  #private;
649
649
  private static MAX_TIMEOUT;
650
650
  private static MAX_RETRY;
@@ -731,35 +731,6 @@ declare class ResultRetry<T, E> implements PromiseLike<Result<T, E>> {
731
731
  * ```
732
732
  */
733
733
  $handle(f: (controller: ResultRetryController<E>) => void): ResultRetry<T, E>;
734
- /**
735
- * Returns {@link ResultAsync} which resolves to this retried {@link Result}.
736
- *
737
- * @example
738
- *
739
- * ```ts
740
- * const result: Result<string, SomeError> = await Result
741
- * .$retry(someResultFn)
742
- * .$times(3)
743
- * .$delay(100)
744
- * .$async()
745
- * .$andThen((message) => `Success: ${message}`)
746
- * .$mapErr((code) => new SomeError({ code }));
747
- * ```
748
- */
749
- $async(this: ResultRetry<T, E>): ResultAsync<T, E>;
750
- /**
751
- * Returns a `Promise` which resolves to this retried {@link Result}.
752
- *
753
- * @example
754
- *
755
- * ```ts
756
- * const promise: Promise<Result<string, Error>> = Result
757
- * .$retry(someResultFn)
758
- * .$times(3)
759
- * .$promise();
760
- * ```
761
- */
762
- $promise(this: ResultRetry<T, E>): Promise<Result<T, E>>;
763
734
  private drain;
764
735
  }
765
736
  interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E> {
@@ -1375,6 +1346,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1375
1346
  * ```
1376
1347
  */
1377
1348
  $or<U = T, F = E>(this: Result<T, E>, or: ResultLike<U, F>): Result<T | U, F>;
1349
+ /**
1350
+ * Shorthand for `result.$async().$or(...)`
1351
+ */
1352
+ $orAsync<U = T, F = E>(this: Result<T, E>, or: ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1378
1353
  /**
1379
1354
  * Returns the result returned by the or function, when this result is `Err`.
1380
1355
  *
@@ -1411,6 +1386,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1411
1386
  * ```
1412
1387
  */
1413
1388
  $orElse<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLike<U, F>): Result<T | U, F>;
1389
+ /**
1390
+ * Shorthand for `result.$async().$orElse(...)`
1391
+ */
1392
+ $orElseAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1414
1393
  /**
1415
1394
  * Returns a {@link Result} based on the outcome of the safe function when
1416
1395
  * this result is `Err`.
@@ -1422,6 +1401,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1422
1401
  */
1423
1402
  $orSafe<U = T>(this: Result<T, E>, f: (err: E) => U): Result<T | U, Error>;
1424
1403
  $orSafe<U = T, F = E>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, F>;
1404
+ /**
1405
+ * Shorthand for `result.$async().$orSafe(...)`
1406
+ */
1407
+ $orSafeAsync<U = T>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>): ResultAsync<T | U, Error>;
1408
+ $orSafeAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1409
+ /**
1410
+ * Shorthand for `result.$async().$orSafePromise(...)`
1411
+ */
1412
+ $orSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<T | U, Error>;
1413
+ $orSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1425
1414
  /**
1426
1415
  * Returns the and result, when this result is `Ok`.
1427
1416
  *
@@ -1458,6 +1447,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1458
1447
  * ```
1459
1448
  */
1460
1449
  $and<U = T, F = E>(this: Result<T, E>, and: ResultLike<U, F>): Result<U, E | F>;
1450
+ /**
1451
+ * Shorthand for `result.$async().$and(...)`
1452
+ */
1453
+ $andAsync<U = T, F = E>(this: Result<T, E>, and: ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1461
1454
  /**
1462
1455
  * Returns the and result, when this result is `Ok`.
1463
1456
  *
@@ -1494,6 +1487,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1494
1487
  * ```
1495
1488
  */
1496
1489
  $andThen<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLike<U, F>): Result<U, E | F>;
1490
+ /**
1491
+ * Shorthand for `result.$async().$andThen(...)`
1492
+ */
1493
+ $andThenAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1497
1494
  /**
1498
1495
  * Calls the through function when this result is `Ok` and returns:
1499
1496
  *
@@ -1534,6 +1531,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1534
1531
  * ```
1535
1532
  */
1536
1533
  $andThrough<F = E>(this: Result<T, E>, f: (val: T) => ResultLike<any, F>): Result<T, E | F>;
1534
+ /**
1535
+ * Shorthand for `result.$async().$andThrough(...)`
1536
+ */
1537
+ $andThroughAsync<F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<any, F>): ResultAsync<T, E | F>;
1537
1538
  /**
1538
1539
  * Returns a result based on the outcome of the safe function when this
1539
1540
  * result is `Ok`.
@@ -1548,6 +1549,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1548
1549
  */
1549
1550
  $andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<U, E | Error>;
1550
1551
  $andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<U, E | F>;
1552
+ /**
1553
+ * Shorthand for `result.$async().$andSafe(...)`
1554
+ */
1555
+ $andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
1556
+ $andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1557
+ /**
1558
+ * Shorthand for `result.$async().$andSafePromise(...)`
1559
+ */
1560
+ $andSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<U, E | Error>;
1561
+ $andSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1551
1562
  /**
1552
1563
  * Calls the peek function and returns {@link Result} equivalent to this
1553
1564
  * result.
package/dist/index.d.ts CHANGED
@@ -644,7 +644,7 @@ declare class ResultAsync<T, E> {
644
644
  /**
645
645
  * ## ResultRetry
646
646
  */
647
- declare class ResultRetry<T, E> implements PromiseLike<Result<T, E>> {
647
+ declare class ResultRetry<T, E> extends ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
648
648
  #private;
649
649
  private static MAX_TIMEOUT;
650
650
  private static MAX_RETRY;
@@ -731,35 +731,6 @@ declare class ResultRetry<T, E> implements PromiseLike<Result<T, E>> {
731
731
  * ```
732
732
  */
733
733
  $handle(f: (controller: ResultRetryController<E>) => void): ResultRetry<T, E>;
734
- /**
735
- * Returns {@link ResultAsync} which resolves to this retried {@link Result}.
736
- *
737
- * @example
738
- *
739
- * ```ts
740
- * const result: Result<string, SomeError> = await Result
741
- * .$retry(someResultFn)
742
- * .$times(3)
743
- * .$delay(100)
744
- * .$async()
745
- * .$andThen((message) => `Success: ${message}`)
746
- * .$mapErr((code) => new SomeError({ code }));
747
- * ```
748
- */
749
- $async(this: ResultRetry<T, E>): ResultAsync<T, E>;
750
- /**
751
- * Returns a `Promise` which resolves to this retried {@link Result}.
752
- *
753
- * @example
754
- *
755
- * ```ts
756
- * const promise: Promise<Result<string, Error>> = Result
757
- * .$retry(someResultFn)
758
- * .$times(3)
759
- * .$promise();
760
- * ```
761
- */
762
- $promise(this: ResultRetry<T, E>): Promise<Result<T, E>>;
763
734
  private drain;
764
735
  }
765
736
  interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E> {
@@ -1375,6 +1346,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1375
1346
  * ```
1376
1347
  */
1377
1348
  $or<U = T, F = E>(this: Result<T, E>, or: ResultLike<U, F>): Result<T | U, F>;
1349
+ /**
1350
+ * Shorthand for `result.$async().$or(...)`
1351
+ */
1352
+ $orAsync<U = T, F = E>(this: Result<T, E>, or: ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1378
1353
  /**
1379
1354
  * Returns the result returned by the or function, when this result is `Err`.
1380
1355
  *
@@ -1411,6 +1386,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1411
1386
  * ```
1412
1387
  */
1413
1388
  $orElse<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLike<U, F>): Result<T | U, F>;
1389
+ /**
1390
+ * Shorthand for `result.$async().$orElse(...)`
1391
+ */
1392
+ $orElseAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => ResultLikeAwaitable<U, F>): ResultAsync<T | U, F>;
1414
1393
  /**
1415
1394
  * Returns a {@link Result} based on the outcome of the safe function when
1416
1395
  * this result is `Err`.
@@ -1422,6 +1401,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1422
1401
  */
1423
1402
  $orSafe<U = T>(this: Result<T, E>, f: (err: E) => U): Result<T | U, Error>;
1424
1403
  $orSafe<U = T, F = E>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, F>;
1404
+ /**
1405
+ * Shorthand for `result.$async().$orSafe(...)`
1406
+ */
1407
+ $orSafeAsync<U = T>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>): ResultAsync<T | U, Error>;
1408
+ $orSafeAsync<U = T, F = E>(this: Result<T, E>, f: (err: E) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1409
+ /**
1410
+ * Shorthand for `result.$async().$orSafePromise(...)`
1411
+ */
1412
+ $orSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<T | U, Error>;
1413
+ $orSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<T | U, F>;
1425
1414
  /**
1426
1415
  * Returns the and result, when this result is `Ok`.
1427
1416
  *
@@ -1458,6 +1447,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1458
1447
  * ```
1459
1448
  */
1460
1449
  $and<U = T, F = E>(this: Result<T, E>, and: ResultLike<U, F>): Result<U, E | F>;
1450
+ /**
1451
+ * Shorthand for `result.$async().$and(...)`
1452
+ */
1453
+ $andAsync<U = T, F = E>(this: Result<T, E>, and: ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1461
1454
  /**
1462
1455
  * Returns the and result, when this result is `Ok`.
1463
1456
  *
@@ -1494,6 +1487,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1494
1487
  * ```
1495
1488
  */
1496
1489
  $andThen<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLike<U, F>): Result<U, E | F>;
1490
+ /**
1491
+ * Shorthand for `result.$async().$andThen(...)`
1492
+ */
1493
+ $andThenAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<U, F>): ResultAsync<U, E | F>;
1497
1494
  /**
1498
1495
  * Calls the through function when this result is `Ok` and returns:
1499
1496
  *
@@ -1534,6 +1531,10 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1534
1531
  * ```
1535
1532
  */
1536
1533
  $andThrough<F = E>(this: Result<T, E>, f: (val: T) => ResultLike<any, F>): Result<T, E | F>;
1534
+ /**
1535
+ * Shorthand for `result.$async().$andThrough(...)`
1536
+ */
1537
+ $andThroughAsync<F = E>(this: Result<T, E>, f: (val: T) => ResultLikeAwaitable<any, F>): ResultAsync<T, E | F>;
1537
1538
  /**
1538
1539
  * Returns a result based on the outcome of the safe function when this
1539
1540
  * result is `Ok`.
@@ -1548,6 +1549,16 @@ interface Retuple<T, E> extends RetupleArray<T | E | undefined>, ResultLike<T, E
1548
1549
  */
1549
1550
  $andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<U, E | Error>;
1550
1551
  $andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<U, E | F>;
1552
+ /**
1553
+ * Shorthand for `result.$async().$andSafe(...)`
1554
+ */
1555
+ $andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
1556
+ $andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1557
+ /**
1558
+ * Shorthand for `result.$async().$andSafePromise(...)`
1559
+ */
1560
+ $andSafePromise<U = T>(this: Result<T, E>, promise: PromiseLike<U>): ResultAsync<U, E | Error>;
1561
+ $andSafePromise<U = T, F = E>(this: Result<T, E>, promise: PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1551
1562
  /**
1552
1563
  * Calls the peek function and returns {@link Result} equivalent to this
1553
1564
  * result.
package/dist/index.js CHANGED
@@ -150,8 +150,6 @@ function $resolve(result) {
150
150
  switch (true) {
151
151
  case result instanceof ResultAsync:
152
152
  return result;
153
- case result instanceof ResultRetry:
154
- return new ResultAsync(result);
155
153
  case result instanceof ResultOk:
156
154
  case result instanceof ResultErr:
157
155
  return new ResultAsync(Promise.resolve(result));
@@ -728,22 +726,43 @@ class ResultOk extends RetupleArray {
728
726
  $or() {
729
727
  return this;
730
728
  }
729
+ $orAsync() {
730
+ return this.$async();
731
+ }
731
732
  $orElse() {
732
733
  return this;
733
734
  }
735
+ $orElseAsync() {
736
+ return this.$async();
737
+ }
734
738
  $orSafe() {
735
739
  return this;
736
740
  }
741
+ $orSafeAsync() {
742
+ return this.$async();
743
+ }
744
+ $orSafePromise() {
745
+ return this.$async();
746
+ }
737
747
  $and(and) {
738
748
  return asResult(and);
739
749
  }
750
+ $andAsync(and) {
751
+ return this.$async().$and(and);
752
+ }
740
753
  $andThen(f) {
741
754
  return asResult(f(this[1]));
742
755
  }
756
+ $andThenAsync(f) {
757
+ return this.$async().$andThen(f);
758
+ }
743
759
  $andThrough(f) {
744
760
  const res = asResult(f(this[1]));
745
761
  return res instanceof ResultErr ? res : this;
746
762
  }
763
+ $andThroughAsync(f) {
764
+ return this.$async().$andThrough(f);
765
+ }
747
766
  $andSafe(f, mapError = ensureError) {
748
767
  try {
749
768
  return Ok(f(this[1]));
@@ -752,6 +771,12 @@ class ResultOk extends RetupleArray {
752
771
  return Err(mapError(err));
753
772
  }
754
773
  }
774
+ $andSafeAsync(f, mapError = ensureError) {
775
+ return this.$async().$andSafe(f, mapError);
776
+ }
777
+ $andSafePromise(promise, mapError = ensureError) {
778
+ return this.$async().$andSafePromise(promise, mapError);
779
+ }
755
780
  $peek(f) {
756
781
  f(this);
757
782
  return this;
@@ -844,9 +869,15 @@ class ResultErr extends RetupleArray {
844
869
  $or(or) {
845
870
  return asResult(or);
846
871
  }
872
+ $orAsync(or) {
873
+ return this.$async().$or(or);
874
+ }
847
875
  $orElse(f) {
848
876
  return asResult(f(this[0]));
849
877
  }
878
+ $orElseAsync(f) {
879
+ return this.$async().$orElse(f);
880
+ }
850
881
  $orSafe(f, mapError = ensureError) {
851
882
  try {
852
883
  return Ok(f(this[0]));
@@ -855,18 +886,39 @@ class ResultErr extends RetupleArray {
855
886
  return Err(mapError(err));
856
887
  }
857
888
  }
889
+ $orSafeAsync(f, mapError = ensureError) {
890
+ return this.$async().$orSafe(f, mapError);
891
+ }
892
+ $orSafePromise(promise, mapError = ensureError) {
893
+ return this.$async().$orSafePromise(promise, mapError);
894
+ }
858
895
  $and() {
859
896
  return this;
860
897
  }
898
+ $andAsync() {
899
+ return this.$async();
900
+ }
861
901
  $andThen() {
862
902
  return this;
863
903
  }
904
+ $andThenAsync() {
905
+ return this.$async();
906
+ }
864
907
  $andThrough() {
865
908
  return this;
866
909
  }
910
+ $andThroughAsync() {
911
+ return this.$async();
912
+ }
867
913
  $andSafe() {
868
914
  return this;
869
915
  }
916
+ $andSafeAsync() {
917
+ return this.$async();
918
+ }
919
+ $andSafePromise() {
920
+ return this.$async();
921
+ }
870
922
  $peek(f) {
871
923
  f(this);
872
924
  return this;
@@ -1146,7 +1198,7 @@ _ResultAsync_inner = new WeakMap();
1146
1198
  /**
1147
1199
  * ## ResultRetry
1148
1200
  */
1149
- class ResultRetry {
1201
+ class ResultRetry extends ResultAsync {
1150
1202
  static zero() {
1151
1203
  return 0;
1152
1204
  }
@@ -1160,6 +1212,7 @@ class ResultRetry {
1160
1212
  return 0;
1161
1213
  }
1162
1214
  constructor(f) {
1215
+ super(Promise.resolve().then(() => __classPrivateFieldGet(this, _ResultRetry_promise, "f")));
1163
1216
  _ResultRetry_f.set(this, void 0);
1164
1217
  _ResultRetry_promise.set(this, void 0);
1165
1218
  _ResultRetry_times.set(this, 1);
@@ -1172,7 +1225,7 @@ class ResultRetry {
1172
1225
  __classPrivateFieldSet(this, _ResultRetry_promise, this.drain(), "f");
1173
1226
  }
1174
1227
  then(onfulfilled, onrejected) {
1175
- return __classPrivateFieldGet(this, _ResultRetry_promise, "f").then(onfulfilled, onrejected);
1228
+ return super.then(onfulfilled, onrejected);
1176
1229
  }
1177
1230
  /**
1178
1231
  * Sets the maximum number of times the retry function can be executed,
@@ -1242,39 +1295,6 @@ class ResultRetry {
1242
1295
  __classPrivateFieldSet(this, _ResultRetry_handler, f, "f");
1243
1296
  return this;
1244
1297
  }
1245
- /**
1246
- * Returns {@link ResultAsync} which resolves to this retried {@link Result}.
1247
- *
1248
- * @example
1249
- *
1250
- * ```ts
1251
- * const result: Result<string, SomeError> = await Result
1252
- * .$retry(someResultFn)
1253
- * .$times(3)
1254
- * .$delay(100)
1255
- * .$async()
1256
- * .$andThen((message) => `Success: ${message}`)
1257
- * .$mapErr((code) => new SomeError({ code }));
1258
- * ```
1259
- */
1260
- $async() {
1261
- return new ResultAsync(this);
1262
- }
1263
- /**
1264
- * Returns a `Promise` which resolves to this retried {@link Result}.
1265
- *
1266
- * @example
1267
- *
1268
- * ```ts
1269
- * const promise: Promise<Result<string, Error>> = Result
1270
- * .$retry(someResultFn)
1271
- * .$times(3)
1272
- * .$promise();
1273
- * ```
1274
- */
1275
- $promise() {
1276
- return Promise.resolve(this);
1277
- }
1278
1298
  async drain() {
1279
1299
  var _b;
1280
1300
  while (__classPrivateFieldGet(this, _ResultRetry_attempt, "f") < __classPrivateFieldGet(this, _ResultRetry_times, "f")) {
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.18",
4
4
  "scripts": {
5
5
  "test": "vitest",
6
6
  "lint": "eslint . --ext .ts -c eslint.config.mjs --fix",