From e062eb55b3158663b24114db81032cf1c84764c0 Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Thu, 24 Apr 2025 14:26:39 -0700 Subject: [PATCH] feat: Add unwrap methods to Ok and Err classes --- src/shared/core/Result.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shared/core/Result.ts b/src/shared/core/Result.ts index 11d16dca..0077fd4d 100644 --- a/src/shared/core/Result.ts +++ b/src/shared/core/Result.ts @@ -21,6 +21,10 @@ export class Ok { public isErr(): this is Err { return false; } + + public unwrap(): T { + return this.value; + } } /** @@ -44,6 +48,10 @@ export class Err { public isErr(): this is Err { return true; } + + public unwrap(): T { + throw this.error; + } } /** @@ -91,7 +99,6 @@ export const combine = (results: Result[]): Result => { return ok(values); }; - // --- Either Type (kept separate for now) --- export type Either = Left | Right; -- 2.51.2