-
Notifications
You must be signed in to change notification settings - Fork 449
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
Add attempt builder as an imperative alternative to recover
#3340
base: arrow-2
Are you sure you want to change the base?
Conversation
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.
Interesting addition!
I am unsure about this addition. My immediate thoughts are that early returning is considered a code-smell by many, and I am not sure what additional patterns this enables? If we want to easily allow transforming the error, which is what I see mostly here perhaps we need a variant of |
val errorList = attempt { return block(RaiseAccumulate(this)) } | ||
addErrors(errorList) | ||
return EmptyValue |
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.
Sorry, here also really not fan of the early return 😅
I had to read this snippets too many times to understand what's going on :/
I understand that early returns are quite controversial. I think, however, that it can be really nice to use whenever the error path is more complicated than the happy path. For instance, trying out different methods until one succeeds becomes really easy (similar to
Of course, this can be done with Another place where I used
The second |
Okay, thank you for clarifying.
Well, it's up to all of us together 😉 I added arrow 2.0 tag, so lets this sink in a bit while we focus on 1.2.2. |
My 2 cents here is that |
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.
I think in this form this can be included in Arrow; maybe not the style we want to promote, but useful in some cases
The goal of this builder is to allow early-returning the "happy path" and thus handling the "error path" in the code that follows.
I couldn't add this in
main
because it conflicted with a deprecated method, and so it wasn't useable inside of otherRaise
instances. Perhaps if there's a better name thanattempt
, then this change can be backported.