title: Scala transform list of tuples to a tuple of lists
body: <p>How can I transform a list of tuples <code>List[(A,B)]</code> to a tuple of lists <code>(List[A], List[B])</code>?</p>
  
  <p>I have tried for following but it looks crude and I was hoping there was a better way of doing this</p>
  
  <pre><code>  val flat: List[AnyRef] = aAndB.map{ x =&gt;
      x.map(y =&gt; List(y._1, y._2))
    }.flatMap(x =&gt; x)
  
    val typeA: List[A] = flat.filter {
      case x: A =&gt; true
      case _ =&gt; false
    }.map(_.asInstanceOf[A])     
  
    val typeB: List[B] = flat.filter {
      case x: B =&gt; true
      case _ =&gt; false
    }.map(_.asInstanceOf[B])
  </code></pre>