Basically, if you have a method that returns a future, and you want to filter a list based on those futures (and the futures are built using values from the list), is there something simple that I can use out of the box?
scala> val nums = 0 to 10
res17: scala.collection.immutable.Range.Inclusive = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> def lookup(id: Int): Future[Option[Int]] = future { if (rnd.nextBoolean) Some(5) else None }
lookup: (id: Int)scala.concurrent.Future[Option[Int]]
scala> val collapsed = Future.sequence(nums.map { n => lookup(n).map { (n, _) } })
reduced: scala.concurrent.Future[scala.collection.immutable.IndexedSeq[(Int, Option[Int])]] = scala.concurrent.impl.Promise$DefaultPromise@5f0900d2
scala> val filtered = collapsed.map { results => results.collect { case (i, opt) if opt.isDefined => i } }
filtered: scala.concurrent.Future[scala.collection.immutable.IndexedSeq[Int]] = scala.concurrent.impl.Promise$DefaultPromise@7f5451cc