retuple 1.0.0-next.32 → 1.0.0-next.33

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
@@ -704,6 +704,18 @@ class ResultOk extends Array {
704
704
  $andSafeAsync(f, mapError = ensureError) {
705
705
  return this.$async().$andSafe(f, mapError);
706
706
  }
707
+ $andThroughSafe(f, mapError = ensureError) {
708
+ try {
709
+ f(this[1]);
710
+ return this;
711
+ }
712
+ catch (err) {
713
+ return Err(mapError(err));
714
+ }
715
+ }
716
+ $andThroughSafeAsync(f, mapError = ensureError) {
717
+ return this.$async().$andThroughSafe(f, mapError);
718
+ }
707
719
  $andSafePromise(promise, mapError = ensureError) {
708
720
  return this.$async().$andSafePromise(promise, mapError);
709
721
  }
@@ -876,6 +888,12 @@ class ResultErr extends Array {
876
888
  $andSafeAsync() {
877
889
  return this.$async();
878
890
  }
891
+ $andThroughSafe() {
892
+ return this;
893
+ }
894
+ $andThroughSafeAsync() {
895
+ return this.$async();
896
+ }
879
897
  $andSafePromise() {
880
898
  return this.$async();
881
899
  }
@@ -1191,6 +1209,20 @@ class ResultAsync {
1191
1209
  }
1192
1210
  }));
1193
1211
  }
1212
+ $andThroughSafe(f, mapError = ensureError) {
1213
+ return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
1214
+ if (res instanceof ResultErr) {
1215
+ return res;
1216
+ }
1217
+ try {
1218
+ await f(res[1]);
1219
+ return res;
1220
+ }
1221
+ catch (err) {
1222
+ return Err(mapError(err));
1223
+ }
1224
+ }));
1225
+ }
1194
1226
  $andSafePromise(promise, mapError = ensureError) {
1195
1227
  return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
1196
1228
  if (res instanceof ResultErr) {
package/dist/index.d.cts CHANGED
@@ -375,6 +375,11 @@ declare class ResultAsync<T, E> {
375
375
  */
376
376
  $andSafe<U = T>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
377
377
  $andSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
378
+ /**
379
+ * @TODO
380
+ */
381
+ $andThroughSafe(this: ResultAsync<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
382
+ $andThroughSafe<F = E>(this: ResultAsync<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
378
383
  /**
379
384
  * Returns {@link ResultAsync} based on the outcome of the promise when this
380
385
  * result is `Ok`.
@@ -1359,6 +1364,16 @@ interface Retuple<T, E> extends ResultLike<T, E> {
1359
1364
  */
1360
1365
  $andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
1361
1366
  $andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1367
+ /**
1368
+ * Shorthand for `result.$andThrough((x) => Result.$safe(() => f(x)))`;
1369
+ */
1370
+ $andThroughSafe(this: Result<T, E>, f: (val: T) => any): Result<T, E | Error>;
1371
+ $andThroughSafe<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): Result<T, E | F>;
1372
+ /**
1373
+ * Shorthand for result.$async().$andThrough(...);
1374
+ */
1375
+ $andThroughSafeAsync(this: Result<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
1376
+ $andThroughSafeAsync<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
1362
1377
  /**
1363
1378
  * Shorthand for `result.$async().$andSafePromise(...)`
1364
1379
  */
package/dist/index.d.ts CHANGED
@@ -375,6 +375,11 @@ declare class ResultAsync<T, E> {
375
375
  */
376
376
  $andSafe<U = T>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
377
377
  $andSafe<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
378
+ /**
379
+ * @TODO
380
+ */
381
+ $andThroughSafe(this: ResultAsync<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
382
+ $andThroughSafe<F = E>(this: ResultAsync<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
378
383
  /**
379
384
  * Returns {@link ResultAsync} based on the outcome of the promise when this
380
385
  * result is `Ok`.
@@ -1359,6 +1364,16 @@ interface Retuple<T, E> extends ResultLike<T, E> {
1359
1364
  */
1360
1365
  $andSafeAsync<U = T>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>): ResultAsync<U, E | Error>;
1361
1366
  $andSafeAsync<U = T, F = E>(this: Result<T, E>, f: (val: T) => U | PromiseLike<U>, mapError: (err: unknown) => F): ResultAsync<U, E | F>;
1367
+ /**
1368
+ * Shorthand for `result.$andThrough((x) => Result.$safe(() => f(x)))`;
1369
+ */
1370
+ $andThroughSafe(this: Result<T, E>, f: (val: T) => any): Result<T, E | Error>;
1371
+ $andThroughSafe<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): Result<T, E | F>;
1372
+ /**
1373
+ * Shorthand for result.$async().$andThrough(...);
1374
+ */
1375
+ $andThroughSafeAsync(this: Result<T, E>, f: (val: T) => any): ResultAsync<T, E | Error>;
1376
+ $andThroughSafeAsync<F = E>(this: Result<T, E>, f: (val: T) => any, mapError: (err: unknown) => F): ResultAsync<T, E | F>;
1362
1377
  /**
1363
1378
  * Shorthand for `result.$async().$andSafePromise(...)`
1364
1379
  */
package/dist/index.js CHANGED
@@ -690,6 +690,18 @@ class ResultOk extends Array {
690
690
  $andSafeAsync(f, mapError = ensureError) {
691
691
  return this.$async().$andSafe(f, mapError);
692
692
  }
693
+ $andThroughSafe(f, mapError = ensureError) {
694
+ try {
695
+ f(this[1]);
696
+ return this;
697
+ }
698
+ catch (err) {
699
+ return Err(mapError(err));
700
+ }
701
+ }
702
+ $andThroughSafeAsync(f, mapError = ensureError) {
703
+ return this.$async().$andThroughSafe(f, mapError);
704
+ }
693
705
  $andSafePromise(promise, mapError = ensureError) {
694
706
  return this.$async().$andSafePromise(promise, mapError);
695
707
  }
@@ -862,6 +874,12 @@ class ResultErr extends Array {
862
874
  $andSafeAsync() {
863
875
  return this.$async();
864
876
  }
877
+ $andThroughSafe() {
878
+ return this;
879
+ }
880
+ $andThroughSafeAsync() {
881
+ return this.$async();
882
+ }
865
883
  $andSafePromise() {
866
884
  return this.$async();
867
885
  }
@@ -1177,6 +1195,20 @@ class ResultAsync {
1177
1195
  }
1178
1196
  }));
1179
1197
  }
1198
+ $andThroughSafe(f, mapError = ensureError) {
1199
+ return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
1200
+ if (res instanceof ResultErr) {
1201
+ return res;
1202
+ }
1203
+ try {
1204
+ await f(res[1]);
1205
+ return res;
1206
+ }
1207
+ catch (err) {
1208
+ return Err(mapError(err));
1209
+ }
1210
+ }));
1211
+ }
1180
1212
  $andSafePromise(promise, mapError = ensureError) {
1181
1213
  return new ResultAsync(__classPrivateFieldGet(this, _ResultAsync_inner, "f").then(async (res) => {
1182
1214
  if (res instanceof ResultErr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retuple",
3
- "version": "1.0.0-next.32",
3
+ "version": "1.0.0-next.33",
4
4
  "scripts": {
5
5
  "test": "vitest",
6
6
  "lint": "eslint . --ext .ts -c eslint.config.mjs --fix",