Skip to content

Commit

Permalink
feat: add unwrap result utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pnodet committed Apr 23, 2024
1 parent d90aa96 commit e789a31
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/result/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ export const valuesFromResults = <T, E>(results: Array<Result<T, E>>): T[] => {

return values;
};

export const unwrap = <T, E>(result: Result<T, E>): T => {
if (result.isOk()) {
return result.value;
}

throw result.error;
};

0 comments on commit e789a31

Please sign in to comment.