我怎麼能轉換Option[Future[T]]
到Future[Option[T]]
在Scala呢?斯卡拉選項[未來[T]給未來的[選項[T]
我想使用它:
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
這裏簽名插入方法
def insert(address: Address): Future[Address]
ca
是一個CustomerData
case class CustomerData(address: Address, invoiceAddress: Option[Address])
所以'一個< - addressDAO.insert(ca.address)'返回一個'未來[選項]'? –
你能指定你的方法的簽名嗎? –
我會用'.sequence'從'與https://github.com/milessabin/si2712fix-plugin scalaz/cats' - 但是這很可能是矯枉過正。 – Reactormonk