findAirline: AirlineCode => Future[Option[Airline]] getFlightsForToday: Airline => Future[Seq[Flight]] findAvailable: Seq[Flight] => Constraints => Future[Option[Flight]
findFlight: AirlineCode => Constraints => Future[Flight]
def 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)