title: partition of a List[Try[String]] in Scala
body: <p>I have a <code>List</code> of <code>Try</code>s, and I need to partition by <code>Failure</code>s and <code>Success</code>es, as follows:</p>
  
  <pre><code>import scala.util.{Try, Success, Failure}
  
  val list = List(Success(10), Success(20), Failure(new Exception("error1")), Success(30))
  
  val (listTryFailures: List[Try[Int]], listTrySuccesses: List[Try[Int]]) = list.partition(_.isFailure)
  listTryFailures: List[Try[Int]] = List(Failure(java.lang.Exception: error1))
  listTrySuccesses: List[Try[Int]] = List(Success(10), Success(20), Success(30))
  
  val (listFailures: List[Throwable], listSuccesses: List[Int]) = (listTryFailures.map(_.failed.get), listTrySuccesses.map(_.get))
  listFailures: List[Throwable] = List(java.lang.Exception: error1)
  listSuccesses: List[Int] = List(10, 20, 30)
  </code></pre>
  
  <p>Is there already a function to achieve this?
  (instead of calling the ugly <code>partition(_.isFailure)</code> + <code>map(_.failed.get)</code> + <code>map(_.get)</code>)?</p>
  
  <p>ps: Another option is as follows:</p>
  
  <pre><code>val listFailures: List[Throwable] = list.collect { case Failure(f) =&gt; f }
  val listSuccesses: List[String] = list.collect { case Success(entry) =&gt; entry }
  
  // or 
  val listFailures: List[Throwable] = list.flatMap(_.failed.toOption)
  val listSuccesses: List[String] = list.flatMap(_.toOption)
  </code></pre>
  
  <p>but I am asking if a <code>partitionSuccess</code> (or similar name) function already exists in a standard library:</p>
  
  <pre><code>val (listFailures: List[Throwable], listSuccesses: List[Int]) = list.partitionSuccess
  </code></pre>