Skip to content

Instantly share code, notes, and snippets.

@mattdenner
Created February 3, 2013 20:38
Show Gist options
  • Select an option

  • Save mattdenner/4703562 to your computer and use it in GitHub Desktop.

Select an option

Save mattdenner/4703562 to your computer and use it in GitHub Desktop.
sealed trait Validation[+E, +A] {
def fold[X](failure: E => X = identity[E] _, success: A => X = identity[A] _): X
def map[B](f: A => B): Validation[E, B];
}
final case class Success[E, A](a: A) extends Validation[E, A] {
def fold[X](failure: E => X = identity[E] _, success: A => X = identity[A] _): X = success(a)
def map[B](f: A => B): Validation[E, B] = Success(f(a))
}
final case class Failure[E, A](e: E) extends Validation[E, A] {
def fold[X](failure: E => X = identity[E] _, success: A => X = identity[A] _): X = failure(e)
def map[B](f: A => B): Validation[E, B] = Failure(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment