Skip to content

Instantly share code, notes, and snippets.

@jbgi
Last active April 21, 2017 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbgi/56079514dde4869f9403b9069aa53365 to your computer and use it in GitHub Desktop.
Save jbgi/56079514dde4869f9403b9069aa53365 to your computer and use it in GitHub Desktop.
Minimal Either sum type in Scala
sealed trait Either[A, B]
final case class Left[A, B](a: A) extends Either[A, B]
final case class Right[A, B](b: B) extends Either[A, B]
object Either {
def left[A, B](a: A): Either[A, B] = Left(a)
def right[A, B](b: B): Either[A, B] = Right(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment