Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2017 00:44
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A few ways to flatten down a Seq[Try] to only Success values
import scala.util.{Success, Failure}
val seq=Seq(Success(1), Failure(new Exception("bang")), Success(2))
// all emit List(1, 2)
seq.collect{case Success(x) => x}
// if you wish to also handle failures, not just ignore
// emit List(1, 2)
// emit List(java.lang.Exception: bang)
val (successes, failures)=seq.partition(_.isSuccess)
failures.collect{case Failure(ex) => ex}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment