-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
unwrap*
methods for Option
and some tweaks
- Loading branch information
Showing
5 changed files
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{# This file is part of DBL, released under MIT license. | ||
# See LICENSE for details. | ||
#} | ||
|
||
import open /Base/Types | ||
import open /Base/Assert | ||
|
||
{## For `Some x` returns `x`, otherwise the provided argument is returned. | ||
#} | ||
pub method unwrapOr default = | ||
match self with | ||
| None => default | ||
| Some x => x | ||
end | ||
|
||
{## This method should only be called on `Some x` values, in which case it | ||
returns `x`. When applied to `None` the entire program crashes irrecoverably | ||
with a runtime error. The resulting error message can be optionally specified | ||
with `?msg`. | ||
#} | ||
pub method unwrap {?msg} = | ||
match self with | ||
| None => runtimeError (msg.unwrapOr "Called `unwrap` on `None`") | ||
| Some x => x | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters