-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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:
fun send(body: T) : Either<ExternalFailure, ExternalSuccess> {
// implementation
}
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 a RuntimeException 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 is Left. So I need something like this:
return send(myBody).getOrElseThrow({ left ->
ProtocolIOException("Something bad had happened :${left}")
})
I do not need to mapLeft, or getOrElse or anything - I just need to return the ExternalSuccess (the Right in my case), or I need to throw an exception.
Is there any built-in way to do so?