我想链接在斯卡拉期货,但它给了我错误的返回类型。链斯卡拉期货返回类型
我有以下几种方法:
def getOneRecordByModel(x:DirectFlight): Future[Option[FlightByDetailModel]] = {
select.allowFiltering().where(_.from eqs x.from).and(_.to eqs x.to).and(_.departure eqs x.departure).and(_.arrival eqs x.arrival).and(_.carrier eqs x.airline).and(_.code eqs x.flightCode).one()
}
def getRecordByUUID(x:FlightByDetailModel): Future[Option[FlightByUUIDModel]] = {
select.allowFiltering().where(_.uuid eqs x.uuid).one()
}
def getUUIDRecordByModel(x:DirectFlight): Future[Option[FlightByUUIDModel]] = {
getOneRecordByModel(x) andThen {
case Success(Some(flight)) => getRecordByUUID(flight)
case Success(x) => Success(x)
case Failure(x) => Failure(x)
}
}
但现在我得到的错误是,getUUIDRecordByModel
返回类型为Future[Option[FlightByDetailModel]]
如何正确地把它们连?
当你使用和然后你不改变返回类型。你想要flatMap或map取决于另一种方法的返回类型。 – monkjack 2014-09-04 19:31:44
'和Then' combinator纯粹是为了副作用。它始终返回它未被调用的“未来”,保持不变。正如其他人所说,“map”和/或“flatMap”应该是你正在寻找的。 – cmbaxter 2014-09-04 19:46:50