Skip to content

Commit

Permalink
FEAT: Add okOr which picks a default value inplace or an error
Browse files Browse the repository at this point in the history
  • Loading branch information
ahme-dev committed May 24, 2023
1 parent d58ee08 commit 54c4ae0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export function isError<T>(possibleErr: Result<T>): possibleErr is Error {
return possibleErr instanceof Error;
}

export function okOr<T>(result: Result<T>, orValue: T) {
if (isError(result)) return orValue;
else return result;
}

export async function tryAsync<T>(promise: Promise<T>): Promise<Result<T>> {
try {
const ok = await promise;
Expand Down

0 comments on commit 54c4ae0

Please sign in to comment.