Re:On Scala
by the1 on Wednesday June 19, 2013 @07:42AM
(#5904938)
let's say you have more than one future:
compose them so that I get:
I don't want `Future[Option[Flight]]` since Future has own error handling (using Try). No cheating by using scalaz monad transformer.
[ Parent
| on HN ]
Re:On Scala
by yummyfajitas on Wednesday June 19, 2013 @08:13AM
(#5905044)
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)
No idea why you consider using scalaz to be cheating.ah, getOrThrow! nice.