Practical Monads: Dealing with Futures of Options
Matt Fowler
704

Can’t we do something like this ? (sorry haven’t tested it)

Future.sequence(Seq(first,second)).map(_.flatten().sum())
  • Seq(first,second) is a Seq[Future[Option[Int]]
  • Future.sequence(…) is a Future[Seq[Option[Int]]
  • ….map(_.flatten()) is a Future[Seq[Int]
  • (….sum()) is a Future[Int]