As the title mentions.
Having many operations done using EitherT[Future, A, B]
. Sometimes I want map left or right through another operation having signature A => Future[C]
. Other scenario is that EitherT[Future, A, B]
the result of a mapping over a future resulting Future[EitherT[Future, A, B]]
.
How can I elegantly flatten types like:
EitherT[Future, Future[A], Future[B]]
and Future[EitherT[Future, A, B]]
Thank you in advance.
In all your cases you can use
EitherT#flatMap
(orEitherT#flatMapF
), in combination with lifting some value toEitherT
(or disjunction (\/
) withflatMapF
).Mapping a
B => F[C]
over anEitherT[F, A, B]
:flatMap
+ liftMapping a
A => F[C]
over anEitherT[F, A, B]
:swap
+flatMap
+ liftMapping an
A => Either[F, B, C]
to anF[A]
:lift +
flatMap