diff --git a/app/src/lib/utilities/result.ts b/app/src/lib/utilities/result.ts new file mode 100644 index 0000000..0eae29d --- /dev/null +++ b/app/src/lib/utilities/result.ts @@ -0,0 +1,22 @@ +export class Result { + private constructor( + private readonly isSuccess: boolean, + public readonly value?: T, + public readonly error?: E) {} + + public static ok(value: T): Result { + return new Result(true, value); + } + + public static fail(error: E): Result { + return new Result(false, null, error); + } + + public isOk(): this is Result { + return this.isSuccess; + } + + public isErr(): this is Result { + return !this.isSuccess; + } +} \ No newline at end of file