Scala Option[Future[T]] to Future[Option[T]]
问题 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]) 回答1: import scala