I have two methods that already exist:
def methodB(): Future[Either[Error, Value]]
def methodC(futureValue: Future[Value]): Future[Value]
And I need a method that will get a result from methodB
and put right value to methodC
but it should be Future:
def methodA(): Future[Either[Error, Value]] = {
val resultFromB: Future[Either[Error, Value]] = methodB()
// get Future[Value] from resultFromB and put it to methodC
resultFromB
}
Could you please help? Maybe how to convert Future[Either[Error, Value]]
to Either[Future[Error], Future[Value]]
?
Getting
Future[Value]
fromFuture[Either[Error, Value]]
is straightforward, though you need a default value in case it isLeft
rather thanRight
:Converting
Future[Either[Error, Value]]
toEither[Future[Error], Future[Value]]
is pointless, because you cannot decide if the outerEither
isLeft
orRight
until the originalFuture
is complete, in which case there is no point in making the inner valuesFuture
s.