Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Created August 8, 2012 20:54
Show Gist options
  • Save mpilquist/3298701 to your computer and use it in GitHub Desktop.
Save mpilquist/3298701 to your computer and use it in GitHub Desktop.
val m: Map[Int, Either[Int, String]] = ...
val rights = m.collect { case (k, Right(v)) => k -> v }
val lefts = m.collect { case (k, Left(v)) => k -> v }
val m: Map[Int, Int \/ String] = ...
val rights = m.collect { case (k, v) if v.isRight => k -> v.toOption.get }
val lefts = m.collect { case (k, v) if v.isLeft => k -> v.swap.toOption.get }
val n: ValidationNEL[String, Int] = ...
n match {
case Success(n) if n > 0 => ...
case Success(_) => ...
case Failure(err) => ...
}
n fold (
err => ...,
n => if (n > 0) ... else ...
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment