Add attempt builder as an imperative alternative to recover#3340
Add attempt builder as an imperative alternative to recover#3340kyay10 wants to merge 1 commit intoarrow-kt:arrow-2from
recover#3340Conversation
|
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.
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 |
serras
left a comment
There was a problem hiding this comment.
I think in this form this can be included in Arrow; maybe not the style we want to promote, but useful in some cases
|
I keep running into issues with this in personal projects, specifically KT-40124, so I'll turn it into a draft for now. We can revisit once that bug is fully fixed (partial mitigation has happened in 2.3, but I still ran into it in more complicated code) |
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
mainbecause it conflicted with a deprecated method, and so it wasn't useable inside of otherRaiseinstances. Perhaps if there's a better name thanattempt, then this change can be backported.