How can I convert Option[Future[T]]
to Future[Option[T]]
in scala?
I want to use it in:
val customerAddresses = for {
a <- addressDAO.insert(ca.address) // Future[Address]
ia <- ca.invoiceAddress.map(addressDAO.insert) // Option[Future[Address]]
} yield (a, ia) // Invalid value have to be two futures
Here signature insert method
def insert(address: Address): Future[Address]
ca
is a CustomerData
case class CustomerData(address: Address, invoiceAddress: Option[Address])
a <- addressDAO.insert(ca.address)
returns aFuture[Option]
? – Distend.sequence
fromscalaz/cats
with github.com/milessabin/si2712fix-plugin - but that would probably be overkill. – Plumbic.sequence
for this it doesn't work until I realize there are conflicting implicits in scope, so if you moveimport cats.implicits._
directly above the call to.sequence
then it works. – Sporting