KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is it possible in scala to specialize on the conditions inside an if within a for comprehension? I'm thinking along the lines of: val collection: SomeGenericCollection[Int] = ... trait CollectionFilter case object Even extends CollectionFilter case object Odd extends CollectionFilter val evenColl = for { i <- collection if(Even) } yield i //evenColl would be a SomeGenericEvenCollection instance val oddColl = for { i <- collection if(Odd) } yield i //oddColl would be a SomeGenericOddCollection instance The gist is that by yielding i , 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. The reason I ask is that I saw something that I couldn't figure out (an example can be found on line 33 of this ScalaQuery example . What it does is create a query for a database (i.e. SELECT ... FROM ... WHERE ... ), where I would have expected it to iterate over the results of said query.
Tags (comma-separated)
Save Edits
Cancel