title: Scala: Filtering based on type
body: <p>I'm learning Scala as it fits my needs well but I am finding it hard to structure code elegantly. I'm in a situation where I have a <code>List</code> <code>x</code> and want to create two <code>List</code>s: one containing all the elements of <code>SomeClass</code> and one containing all the elements that aren't of <code>SomeClass</code>.</p>
  
  <pre><code>val a = x collect {case y:SomeClass =&gt; y}
  val b = x filterNot {_.isInstanceOf[SomeClass]}
  </code></pre>
  
  <p>Right now my code looks like that. However, it's not very efficient as it iterates <code>x</code> twice and the code somehow seems a bit hackish. Is there a better (more elegant) way of doing things?</p>
  
  <p>It can be assumed that <code>SomeClass</code> has no subclasses.</p>