@rotomeca/rop 3.0.1 → 4.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.
@@ -74,6 +74,15 @@ class Fail extends internal_1.ATresult {
74
74
  unwrapOr(defaultValue) {
75
75
  return defaultValue;
76
76
  }
77
+ /**
78
+ * Executes the provided function if the result is an error, then returns the original result.
79
+ * @param fn A function to execute with the error value.
80
+ * @returns The original result.
81
+ */
82
+ tapError(fn) {
83
+ fn(this.error);
84
+ return this;
85
+ }
77
86
  /**
78
87
  * Creates a new Fail instance.
79
88
  * @param error The error value.
@@ -73,6 +73,14 @@ class Success extends internal_1.ATresult {
73
73
  unwrapOr(_) {
74
74
  return this.value;
75
75
  }
76
+ /**
77
+ * Executes the provided function if the result is an error, then returns the original result.
78
+ * @param _ Unused function since this is a Success.
79
+ * @returns The original Success result.
80
+ */
81
+ tapError(_) {
82
+ return this;
83
+ }
76
84
  /**
77
85
  * Creates a new Success instance.
78
86
  * @param value The success value.
@@ -55,6 +55,12 @@ export declare class Fail<TSuccess, TE = Error> extends ATresult<TSuccess, TE> {
55
55
  * @returns The success value if the result is a success, otherwise the default value.
56
56
  */
57
57
  unwrapOr(defaultValue: TSuccess): TSuccess;
58
+ /**
59
+ * Executes the provided function if the result is an error, then returns the original result.
60
+ * @param fn A function to execute with the error value.
61
+ * @returns The original result.
62
+ */
63
+ tapError(fn: (error: TE) => void): ITResult<TSuccess, TE>;
58
64
  /**
59
65
  * Creates a new Fail instance.
60
66
  * @param error The error value.
@@ -71,6 +71,15 @@ export class Fail extends ATresult {
71
71
  unwrapOr(defaultValue) {
72
72
  return defaultValue;
73
73
  }
74
+ /**
75
+ * Executes the provided function if the result is an error, then returns the original result.
76
+ * @param fn A function to execute with the error value.
77
+ * @returns The original result.
78
+ */
79
+ tapError(fn) {
80
+ fn(this.error);
81
+ return this;
82
+ }
74
83
  /**
75
84
  * Creates a new Fail instance.
76
85
  * @param error The error value.
@@ -54,6 +54,12 @@ export declare class Success<TSuccess, TE = Error> extends ATresult<TSuccess, TE
54
54
  * @returns The success value if the result is a success, otherwise the default value.
55
55
  */
56
56
  unwrapOr(_: TSuccess): TSuccess;
57
+ /**
58
+ * Executes the provided function if the result is an error, then returns the original result.
59
+ * @param _ Unused function since this is a Success.
60
+ * @returns The original Success result.
61
+ */
62
+ tapError(_: (error: TE) => void): ITResult<TSuccess, TE>;
57
63
  /**
58
64
  * Creates a new Success instance.
59
65
  * @param value The success value.
@@ -70,6 +70,14 @@ export class Success extends ATresult {
70
70
  unwrapOr(_) {
71
71
  return this.value;
72
72
  }
73
+ /**
74
+ * Executes the provided function if the result is an error, then returns the original result.
75
+ * @param _ Unused function since this is a Success.
76
+ * @returns The original Success result.
77
+ */
78
+ tapError(_) {
79
+ return this;
80
+ }
73
81
  /**
74
82
  * Creates a new Success instance.
75
83
  * @param value The success value.
@@ -51,6 +51,12 @@ export declare abstract class ATresult<Success, E = Error> implements ITResult<S
51
51
  * @returns The success value if the result is a success, otherwise the default value.
52
52
  */
53
53
  abstract unwrapOr(defaultValue: Success): Success;
54
+ /**
55
+ * Executes the provided function if the result is an error, then returns the original result.
56
+ * @param fn A function to execute with the error value.
57
+ * @returns The original result.
58
+ */
59
+ abstract tapError(fn: (error: E) => void): ITResult<Success, E>;
54
60
  /**
55
61
  * Checks if the result is a success.
56
62
  *
@@ -78,4 +78,10 @@ export declare interface ITResult<Success, Error> {
78
78
  * @returns The success value if the result is a success, otherwise the default value.
79
79
  */
80
80
  unwrapOr(defaultValue: Success): Success;
81
+ /**
82
+ * Executes the provided function if the result is an error, then returns the original result.
83
+ * @param fn A function to execute with the error value.
84
+ * @returns The original result.
85
+ */
86
+ tapError(fn: (error: Error) => void): ITResult<Success, Error>;
81
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotomeca/rop",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",