https://kotlinlang.org logo
Title
f

Filip Piechowski

01/19/2023, 3:05 PM
Hello. I want to both start
either { … }
block and catch any exceptions inside like:
either {
    Either.catch {
        // potentially throwing code
    }.bind()
}
Is there a builtin function for such case? something like
eitherCatch { … }
s

simon.vergauwen

01/19/2023, 3:14 PM
Such a function is not available yet, and you need context receivers to define it 😕 We're working on such functions though, but since working with
Either
is typically over
E
the function is currently prototyped as:
either<Error, A> {
  val a: A = catch(
   { // throwing code },
   { e: Throwable ->
     // shift(e.toError())
     // transform(e).bind()
     // return fallback A
   })
   a
}