I post a PR where i use `Either.catch {}` on some...
# arrow
j
I post a PR where i use
Either.catch {}
on some network calls, one comment was that using a
try/catch
is more explicit. how could you sell the idea that
Either.catch {}
is better than usual
try/catch
. For me, the way it looks y just clean, but they think the other way, for them is more clear an imperative style. I don’t wanna get back to
try/catch
😂
g
I believe it depends on way how you use it
I would also pointed out on code which doing something like Either.catch { }.fold({ someErrorHandlin() }, { doSomething(it) } It’s not something better than try/catch
b
It's conceptually the same thing but one could argue that if you codebase uses Arrow a lot, removing the fold to handle the error later would make it a smaller refactoring. But yeah, that's a minor detail, we're only talking about 1 line of code here
g
Even if code uses Arrow a lot, using fold on place looks not correct for me, it’s not functional approach, it’s just unnecessary abstraction on top of try/catch If you propagate this Either (return as result) it’s another story of course
👍 1
j
Yes, actuallty what we do is to propagate the resulting either from
Either.catch {}
to a controller where the Either.fold is applied over.
Copy code
fun getIdsFromUsersWithoutAlternatives2fa(): Either<ApiError, List<String>> = Either.catch {   
     val query = GET_USER_ID_FROM_USERS_WITHOUT_ALTERNATIVE_2FA
     val queryExecutionId = submitAthenaQuery(query)
     waitForQueryToComplete(queryExecutionId)
     processQueryResult(queryExecutionId)
}.mapLeft { error -> ApiError("Error occurred while querying athena", cause = error as Exception) }
g
This example makes sense imo, after all Either is propagated
b
Even if the either isn't propagated, the fact that it uses a suspend function indicates that it is impure, which isn't the case with runCatching