Having recently read an insightful article on Handling Failure by Vladimir Khorikov, I was inspired to try implementing the concept in TypeScript.
The original C# code example provided a solid foundation, although the technical details were beyond my current understanding.
This is where I currently stand with my implementation:
export class Result<T> {
success: boolean;
private error: string | null;
private _value: T;
get value(): T {
if (!this.success) {
throw new Error('Cannot get value of an error result.');
}
return this._value;
}
// More code follows...
I find myself struggling to incorporate the chain functions as demonstrated in the example code. While the onSuccess
, onFailure
, and onBoth
functions work seamlessly in the provided code snippet, I am only able to invoke void functions in my own implementation. Passing results to subsequent functions seems to be a challenge.
If anyone could offer guidance or suggestions on how to properly implement this chaining functionality, I would greatly appreciate it.