Hi dotty folks, not sure if this is the best place to post this question. I’ve already tried gitter and users.scala-lang.org does not have a dotty dedicated section.
Out of curiosity, I’ve been looking at union types, trying to get a feel for whether their current implementation would allow for a partial recovery extension method on Either, which would essentially look like this :
case class Error1()
case class Error2()
val a : Either[Error1 | Error2, Int] = ???
val b = either.recoverOn[Error1](e1 => 0) // b inferred to Either[Error2, Int]
I’ve been bashing my head against the wall for hours on a few evenings, using my Scala2 knowledge of implicits resolution, Aux patterns, partially applied functions, etc, but keep falling short. I’ve also tried reducing the problem to obtain the following, still without success :
case class A()
case class B()
val ab : A | B = A()
// turning a union into an either as an extension method
val res1 : Either[A, B] = ab.split[A]
val res2 : Either[B, A] = ab.split[B]
without success.
So my question is : should this be possible ?
EDIT, closest I got to is this https://scastie.scala-lang.org/SKpvIekJSXyM3hLRkoWcwQ