title: Scala's for-comprehension `if` statements
body: <p>Is it possible in scala to specialize on the conditions inside an <code>if</code> within a for comprehension? I'm thinking along the lines of:</p>
  
  <pre><code>val collection: SomeGenericCollection[Int] = ...
  
  trait CollectionFilter
  case object Even extends CollectionFilter
  case object Odd extends CollectionFilter
  
  val evenColl = for { i &lt;- collection if(Even) } yield i
  //evenColl would be a SomeGenericEvenCollection instance
  
  val oddColl = for { i &lt;- collection if(Odd) } yield i
  //oddColl would be a SomeGenericOddCollection instance
  </code></pre>
  
  <p>The gist is that by yielding <code>i</code>, I get a new collection of a potentially different type (hence me referring to it as "specialization")- as opposed to just a filtered-down version of the same GenericCollection type.</p>
  
  <p>The reason I ask is that I saw something that I couldn't figure out (an example can be found <a href="https://github.com/szeiger/scalaquery-examples/blob/master/src/main/scala/org/scalaquery/examples/UseInvoker.scala" rel="noreferrer">on line 33 of this ScalaQuery example</a>. What it does is create a query for a database (i.e. <code>SELECT ... FROM ... WHERE ...</code>), where I would have expected it to iterate over the results of said query.</p>