-
Notifications
You must be signed in to change notification settings - Fork 453
Either introduce getOrElseThrow method #3598
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
Comments
I can provide a PR if needed. We have implemented this function as an extension to karrow |
That's just: return send(myBody).getOrElse { left ->
throw ProtocolIOException("Something bad had happened :${left}")
} |
Yes, that can be done this way, I know, but this function is in general meant to compute the default value in case we have You are correct @kyay10, but my point is that it may be a good idea to have a dedicated method for it? I'm not insisting, just sharing my thoughts that calling |
Part of the intention of having such a type is that you can pass in an |
@kyay10 So, should I try to submit the PR and we'll see how it goes? |
ping here @kyay10 :) |
I agree here with @kyay10, the idiomatic way to handle this in Kotlin is writing |
I have not found any appropriate issue, so I'm leaving it here.
So, assume we have the following function that returns the karrow
Either
:What it does is it sends over a specific protocol some information, it does not matter for this issue. What I need is to call the function
send(body: t)
, and I need to throw aRuntimeException
to the callee, in case we hit an error. This is the contract that I have to adhere to.The way I should recognize that the error had happened is by checking if the
Either
isLeft
. So I need something like this:I do not need to
mapLeft
, orgetOrElse
or anything - I just need to return theExternalSuccess
(theRight
in my case), or I need to throw an exception.Is there any built-in way to do so?
The text was updated successfully, but these errors were encountered: