Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Reimplement Maybe.unwrap() in terms of Maybe.expect()
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Feb 24, 2020
1 parent 64f1403 commit dde5a63
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/Maybe.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ export default class Maybe<T> {
* Otherwise, will throw a runtime exception.
*/
unwrap(): T {
const m = this._m;
if (m.type === Just) {
return m.value;
} else {
throw new Error('Cannot unwrap a Nothing');
}
return this.expect('Cannot unwrap a Nothing');
}

expect(message: string | Error): T {
Expand Down

0 comments on commit dde5a63

Please sign in to comment.