Skip to content

[Junie]: Junie Either introduce getOrElseThrow method#7

Closed
junie-eap[bot] wants to merge 1 commit intomainfrom
junie-issue-4
Closed

[Junie]: Junie Either introduce getOrElseThrow method#7
junie-eap[bot] wants to merge 1 commit intomainfrom
junie-issue-4

Conversation

@junie-eap
Copy link
Copy Markdown

@junie-eap junie-eap bot commented Apr 28, 2025

📌 Hey! This PR was made for you with Junie, the coding agent by JetBrains Early Access Preview

It's still learning, developing, and might make mistakes. Please make sure you review the changes before you accept them.
We’d love your feedback — join our Discord to share bugs, ideas: here.

📝 Original Issue Description

  Issue task:
  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).throwOnLeft({ 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?

  Issue comments:
  No comments yet

📊 Junie Summary

A throwOnLeft method was added to the Either class to throw a RuntimeException when encountering a Left value, consistent with the specified contract. The implementation was error-free, and all tests, including new tests for this functionality, passed successfully.

@nomisRev nomisRev closed this May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant