4 ms·
let's say you have more than one future: findAirline: AirlineCode => Future[Option[Airline]] getFlightsForToday: Airline =>
by the1 13y ago
let's say you have more than one future:
findAirline: AirlineCode => Future[Option[Airline]]
getFlightsForToday: Airline => Future[Seq[Flight]]
findAvailable: Seq[Flight] => Constraints => Future[Option[Flight]
compose them so that I get:
findFlight: AirlineCode => Constraints => Future[Flight]
I don't want `Future[Option[Flight]]` since Future has own error handling (using Try). No cheating by using scalaz monad transformer.
- yummyfajitas 13y agodef getOrThrow[T](x: Option[T]): T = x.getOrElse(throw new AirlineError) def findFlight(code: AirlineCode, constraints: Constraints) = for { airline <- findAirline(code).map(getOrThrow) flights <- getFlightsForToday(airline) available <- findAvailable(flights, constraints).map(getOrThrow) } yield (available) No idea why you consider using scalaz to be cheating.
- the1 13y agoah, getOrThrow! nice.
- saryant 13y agoI'll readily admit that my Scala isn't 100% idiomatic, I'm still learning!