-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Result<T>.OrThrow() #18
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes you just need an exception, even if avoiding them is a goal of this library. Examples include situations where you are defining a custom type that has
Parse()
andTryParse()
methods that both point to a common method returningResult<T>
.Currently it is possible to accomplish something similar to the proposed
OrThrow()
function by doing the following:This feels like an abuse of the
Map
part of theMapOrElse()
pattern. Returning itself is not the intended use.So I'd like to propose the following, which does exactly the same thing as above but with better semantics:
Example usage:
The text was updated successfully, but these errors were encountered: