@rotomeca/rop 4.0.0 → 5.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.
@@ -83,6 +83,14 @@ class Fail extends internal_1.ATresult {
83
83
  fn(this.error);
84
84
  return this;
85
85
  }
86
+ /**
87
+ * Executes the provided function if the result is a success, then returns the original result.
88
+ * @param fn A function to execute with the success value.
89
+ * @returns The original result.
90
+ */
91
+ tap(_) {
92
+ return this;
93
+ }
86
94
  /**
87
95
  * Creates a new Fail instance.
88
96
  * @param error The error value.
@@ -81,6 +81,15 @@ class Success extends internal_1.ATresult {
81
81
  tapError(_) {
82
82
  return this;
83
83
  }
84
+ /**
85
+ * Executes the provided function if the result is a success, then returns the original result.
86
+ * @param fn A function to execute with the success value.
87
+ * @returns The original result.
88
+ */
89
+ tap(fn) {
90
+ fn(this.value);
91
+ return this;
92
+ }
84
93
  /**
85
94
  * Creates a new Success instance.
86
95
  * @param value The success value.
@@ -61,6 +61,12 @@ export declare class Fail<TSuccess, TE = Error> extends ATresult<TSuccess, TE> {
61
61
  * @returns The original result.
62
62
  */
63
63
  tapError(fn: (error: TE) => void): ITResult<TSuccess, TE>;
64
+ /**
65
+ * Executes the provided function if the result is a success, then returns the original result.
66
+ * @param fn A function to execute with the success value.
67
+ * @returns The original result.
68
+ */
69
+ tap(_: (success: TSuccess) => void): ITResult<TSuccess, TE>;
64
70
  /**
65
71
  * Creates a new Fail instance.
66
72
  * @param error The error value.
@@ -80,6 +80,14 @@ export class Fail extends ATresult {
80
80
  fn(this.error);
81
81
  return this;
82
82
  }
83
+ /**
84
+ * Executes the provided function if the result is a success, then returns the original result.
85
+ * @param fn A function to execute with the success value.
86
+ * @returns The original result.
87
+ */
88
+ tap(_) {
89
+ return this;
90
+ }
83
91
  /**
84
92
  * Creates a new Fail instance.
85
93
  * @param error The error value.
@@ -60,6 +60,12 @@ export declare class Success<TSuccess, TE = Error> extends ATresult<TSuccess, TE
60
60
  * @returns The original Success result.
61
61
  */
62
62
  tapError(_: (error: TE) => void): ITResult<TSuccess, TE>;
63
+ /**
64
+ * Executes the provided function if the result is a success, then returns the original result.
65
+ * @param fn A function to execute with the success value.
66
+ * @returns The original result.
67
+ */
68
+ tap(fn: (success: TSuccess) => void): ITResult<TSuccess, TE>;
63
69
  /**
64
70
  * Creates a new Success instance.
65
71
  * @param value The success value.
@@ -78,6 +78,15 @@ export class Success extends ATresult {
78
78
  tapError(_) {
79
79
  return this;
80
80
  }
81
+ /**
82
+ * Executes the provided function if the result is a success, then returns the original result.
83
+ * @param fn A function to execute with the success value.
84
+ * @returns The original result.
85
+ */
86
+ tap(fn) {
87
+ fn(this.value);
88
+ return this;
89
+ }
81
90
  /**
82
91
  * Creates a new Success instance.
83
92
  * @param value The success value.
@@ -57,6 +57,12 @@ export declare abstract class ATresult<Success, E = Error> implements ITResult<S
57
57
  * @returns The original result.
58
58
  */
59
59
  abstract tapError(fn: (error: E) => void): ITResult<Success, E>;
60
+ /**
61
+ * Executes the provided function if the result is a success, then returns the original result.
62
+ * @param fn A function to execute with the success value.
63
+ * @returns The original result.
64
+ */
65
+ abstract tap(fn: (success: Success) => void): ITResult<Success, E>;
60
66
  /**
61
67
  * Checks if the result is a success.
62
68
  *
@@ -84,4 +84,10 @@ export declare interface ITResult<Success, Error> {
84
84
  * @returns The original result.
85
85
  */
86
86
  tapError(fn: (error: Error) => void): ITResult<Success, Error>;
87
+ /**
88
+ * Executes the provided function if the result is a success, then returns the original result.
89
+ * @param fn A function to execute with the success value.
90
+ * @returns The original result.
91
+ */
92
+ tap(fn: (success: Success) => void): ITResult<Success, Error>;
87
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotomeca/rop",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",