dave08
02/21/2023, 4:46 PMclient.runCatching { get("/") }.bind()
?Petr Laštovička
02/21/2023, 4:47 PMdave08
02/21/2023, 4:49 PMA
not `R`:
public inline fun <R, A> Raise<R>.catch(
@BuilderInference action: Raise<R>.() -> A,
@BuilderInference catch: Raise<R>.(Throwable) -> A,
)
Petr Laštovička
02/21/2023, 4:50 PMCLOVIS
02/21/2023, 4:51 PMCLOVIS
02/21/2023, 4:52 PMrunCatching
catches CancellationException
, which is forbidden by the coroutines library (it breaks structured concurrency). To my knowledge Arrow's Either.catch
is fine, but the arrow maintainers can confirmdave08
02/21/2023, 4:56 PMval response = catch({ request() }, { raise(ServerIsDown) })
I had to use raise(..)
, it seems like catch is also a recover mechanism if you return a valid right value instead of raising.phldavies
02/21/2023, 5:05 PMEither.catch
uses t.nonFatalOrThrow().left()
to capture the thrown Throwable
, and rethrow it if it's considered "fatal" (including cancellation) - based on the platform-specific implementation of a NonFatal predicate.simon.vergauwen
02/21/2023, 5:28 PMit seems like catch is also a recover mechanism if you return a valid right value instead of raising.Yes, all these APIs are the same. Where
catch
works over Throwable
, and recover
over E
.
catch
also exists over a reified E
in case you only want to catch
specific errors.
It would be nice to have a KDOC onWhich documentation are you looking at? It's explained in theexplaining that... it's not really clear from it's name.catch()
catch
function on Either<Throwable, A>
is it missing from the DSL version?dave08
02/22/2023, 10:15 AMthis.
and see what Idea pulls up, then I press ctrl-q to get the kdocs in a popup window... it's MUCH easier and faster to discover a new api than to go back and forth to the docs site...dave08
02/22/2023, 10:17 AMsimon.vergauwen
02/22/2023, 10:17 AMEither.catch
is definitely documented though 🤔
https://github.com/arrow-kt/arrow/blob/d07f778795611dead0802d0121f4bd48b421b330/ar[…]libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.ktsimon.vergauwen
02/22/2023, 10:17 AMIf they're both the same, will one be deprecated?One is DSL version, and one is top-level so both will exists alongside each-other.
dave08
02/22/2023, 10:18 AMdave08
02/22/2023, 10:19 AMdave08
02/22/2023, 10:20 AMdave08
02/22/2023, 10:20 AMdave08
02/22/2023, 10:21 AMOne is DSL version, and one is top-level so both will exists alongside each-other. (edited)I see them both in the DSL
simon.vergauwen
02/22/2023, 10:21 AMrecover
is documented and not catch
.simon.vergauwen
02/22/2023, 10:22 AM/** @see catch */
into the KDoc doesn't help since it's ambiguous for overloads and duplicating documentation doesn't seem like a good solution either.simon.vergauwen
02/22/2023, 10:22 AMEither.Companion.catch
is indeed undocumented.dave08
02/22/2023, 10:22 AM/** @see ...*/
s...)dave08
02/22/2023, 10:23 AMdave08
02/22/2023, 10:26 AMsince it's ambiguous for overloadsAdding a
@JvmName
doesn't help there? 🤞🏼CLOVIS
02/22/2023, 10:26 AMCLOVIS
02/22/2023, 10:27 AMCLOVIS
02/22/2023, 10:28 AMdave08
02/22/2023, 10:29 AMCLOVIS
02/22/2023, 10:29 AMCLOVIS
02/22/2023, 10:30 AM