title: scala pattern matching for comprehension
body: <p>In scala can you have a for comprehension that iterates through a List of objects and then makes a Arrays of values based on the type of one of the attributes of the elements?  So assume I have a list of elements and each element has an attribute, and the attribute could be different types...   </p>
  
  <pre><code>for (element &lt;- elementList) element.attribute match {
   case a: Type1 =&gt; "Type1"
   case a =&gt; "All Types"
  }
  </code></pre>
  
  <p>And then the resulting Array would be an array with values like</p>
  
  <pre><code>Array("Type1", "Type1", "All Types", "Type1", "All Types", "All Types", "All Types", "All Types") 
  </code></pre>