From e418bc2bfd19b6c096e6afdf12950d5cb96e9417 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Thu, 22 Feb 2024 23:02:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AE=20Adds=20results=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/utilities/result.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/src/lib/utilities/result.ts 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