I have an
Either type e.g.
Either[A, B] but I want an
Either[X, Y] by using two functions
A => X and
B => Y.
I can do that with fold:
val myEither: Either[A, B] = ... myEither.fold( a => Left(createNewX()), b => Right(createNewY()) )
But that seems redundant to me as I have to repeat the
Right. I rather want something like:
val myEither: Either[A, B] = ... myEither.transformToEither( a => createNewX(), b => createNewY() )
which transforms an
Either[A, B] to an
Either[X, Y] by creating a
Left for the result of the first function and a
Right for the second one. What is the most scala-ish way to do it?