title: Is there sequential Future.find?
body: <p>I have some side-effectful function, </p>
  
  <pre><code>def f(): Future[Int] = {
    val n = Random.nextInt()
    println(s"Generated $n")
    Future(n)
  }
  </code></pre>
  
  <p>and I want to execute it repeatedly until predicate returns true.</p>
  
  <pre><code>def success(n: Int): Boolean = n % 2 == 0
  </code></pre>
  
  <p>My plan is to build <code>Stream</code> of results</p>
  
  <pre><code>val s = Stream.fill(10)(f)
  </code></pre>
  
  <p>and then use <code>Future.find</code> to get the first result that satisfies predicate.</p>
  
  <pre><code>Future.find(s)(success) map println
  </code></pre>
  
  <p>The problem is that <code>Future.find</code> runs all the futures in parallel and I want it to execute futures sequentially one after the other until predicate returns true.</p>
  
  <pre><code>scala&gt; Future.find(s)(success) map println
  Generated -237492703
  Generated -935476293
  Generated -1155819556
  Generated -375506595
  Generated -912504491
  Generated -1307379057
  Generated -1522265611
  Generated 1163971151
  Generated -516152076
  res8: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@37d28f02
  Some(-1155819556)
  </code></pre>
  
  <p>The question is how to execute stream of futures sequentially until predicate returns true? Are there any suitable functions in standard or third-party library?</p>