I've got a Future[Either[A, B]]
and a function providing a Future[C]
from a B
.
I need to transform the Future[Either[A, B]]
to Future[Either[A, C]]
.
Is there a direct way to get the Future[Either[A, C]]
and not a Future[Either[A, Future[C]]]
?
I'm thinking about something like:
val eventuallyInitialValue: Future[Either[A, B]] = ???
val result: Future[Either[A, C]] = for {
e: Either[A, B] <- initialValue
c: C <- service.getValue(e.right)
} yield e.right.map(_ => c)
It's just pseudo-code since service.getValue(e.right)
does not compile. What would be the correct way of doing it?