-
Notifications
You must be signed in to change notification settings - Fork 18
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
results: Add Opt/Result converters #177
Conversation
Notably, the template The "missing piece" here is converting an option to a a result, placing the value of the option in the error of the result, ie flipping them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names okOr
and errOr
seem quite ambiguous to me and errOr
is a no-go, considering that Nim can be style insensitive.
okOr
could simply be named asResult()
.
errOr
is quite a strange API and thus, it's quite difficult to come up with a suitable name. When would I want to optionally create an error value our of the "successful" result of another operation? Perhaps only in some overly monadic code such as:
return someApiResturingResult().optError.errOr:
# a large block of code computing the successful result
... but I could have easily written this in a more natural and performant way.
Yeah, I'm not too happy about
The main case I can think of is after you've used |
Other possible names are |
The Result-general
In In terms of |
I don't feel I'm spending my time productively continuing this conversation, so feel free to ignore my feedback if you are decided on But I don't see how the Otherwise, I was aware of The plain |
Oh, now I see what you meant, let me think.
fwiw, I've considered |
Add `optError`, `optValue`, `okOr` and `errOr` to convert back and forth between Opt and Result - these conversions end up being more common than others since "trivial" success/fail-style API often use Opt while combining such API into combined operations tends to prefer richer error reporting.
`orErr` already covers `okOr`, `errOr` is controversially named _and_ not really that useful
This situation resolved itself rather nicely in that the relevant converter already existed with a good name: what remains to consider there is the other direction: |
Add
optError
,optValue
,okOr
anderrOr
to convert back and forth between Opt and Result - these conversions end up being more common than others since "trivial" success/fail-style API often use Opt while combining such API into combined operations tends to prefer richer error reporting.