Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/lib/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,3 @@ export function err<E>(error: E): Err<E> {
return { ok: false, error };
}

export function isOk<T, E>(r: Result<T, E>): r is Ok<T> {
return r.ok;
}

export function isErr<T, E>(r: Result<T, E>): r is Err<E> {
return !r.ok;
}

export function unwrap<T, E>(r: Result<T, E>): T {
if (r.ok) return r.value;
throw new Error(`unwrap on Err: ${JSON.stringify(r.error)}`);
}

export async function tryAsync<T>(fn: () => Promise<T>): Promise<Result<T, unknown>> {
try {
return ok(await fn());
} catch (e) {
return err(e);
}
}
Loading