export class Result { private constructor( private readonly _isSuccess: boolean, private readonly _value?: T, private readonly _error?: E ) {} public static ok(value: U): Result { return new Result(true, value); } public static fail(error: F): Result { return new Result(false, undefined, error); } public get isSuccess(): boolean { return this._isSuccess; } public get isFailure(): boolean { return !this._isSuccess; } public getValue(): T { if (!this._isSuccess) { throw new Error(`Cannot get value from failed Result: ${this._error}`); } return this._value as T; } public getError(): E { if (this._isSuccess) { throw new Error("Cannot get error from successful Result"); } return this._error as E; } }