[Junie]: Junie Either introduce getOrElseThrow method#7
Closed
junie-eap[bot] wants to merge 1 commit intomainfrom
Closed
[Junie]: Junie Either introduce getOrElseThrow method#7junie-eap[bot] wants to merge 1 commit intomainfrom
junie-eap[bot] wants to merge 1 commit intomainfrom
Conversation
changes from the task: #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 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
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?
📊 Junie Summary
A
throwOnLeftmethod 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.