Practical Monads: Dealing with Futures of Options
Matt Fowler
374

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]
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.