title: Combining Scala Futures and collections in for comprehensions
body: <p>I'm trying to use a for expression to iterate over a list, then do a transformation on each element using a utility that returns a Future. Long story short, it doesn't compile, and I'd like to understand why. I read <a href="https://stackoverflow.com/questions/14349603/unable-to-use-for-comprehension-to-map-over-list-within-future">this question</a>, which is similar, and was a great help, but what I'm trying to do is even simpler, which is all the more confusing as to why it doesn't work. I'm trying to do something like:</p>
  
  <pre><code>import scala.concurrent.Future
  import scala.concurrent.ExecutionContext.Implicits.global
  
  val numberList = List(1, 2, 3)
  def squareInTheFuture(number: Int): Future[Int] = Future { number * number}
  val allTheSquares = for {
                            number &lt;- numberList
                            square &lt;- squareInTheFuture(number)
                          } yield { square }
  </code></pre>
  
  <p>And what I get is:</p>
  
  <blockquote>
    <p>error: type mismatch;
     found   : scala.concurrent.Future[Int]
     required: scala.collection.GenTraversableOnce[?]
           square &lt;- squareInTheFuture(number)
                  ^</p>
  </blockquote>
  
  <p>Can someone help me understand why this doesn't work and what the best alternative is?</p>