Ho uno Future[Either[A, B]]
e una funzione che fornisce un Future[C]
da un B
.Futuro [O [A, B]] a Futuro [O [A, C]] utilizzando una funzione (B => Futuro [C])
Devo trasformare lo Future[Either[A, B]]
in Future[Either[A, C]]
.
C'è un modo diretto per ottenere il Future[Either[A, C]]
e non uno Future[Either[A, Future[C]]]
?
sto pensando a qualcosa di simile:
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)
E 'solo pseudo-codice in quanto service.getValue(e.right)
non compilare. Quale sarebbe il modo corretto di farlo?
Grazie. Deve solo essere restituito come un diritto: bToFC (r) .map (Right (_)) –
@Alban: sì, modificato quello in – Daenyth
Se si utilizza 'Future.successful' invece di' Future.apply' eviterete creando 'Left (e)' su un pool di thread. –