Skip to content

Instantly share code, notes, and snippets.

@tstone
Created July 28, 2014 17:55
Show Gist options
  • Save tstone/027abafe1a7bc9466f9c to your computer and use it in GitHub Desktop.
Save tstone/027abafe1a7bc9466f9c to your computer and use it in GitHub Desktop.
A little shortcut around always having to specify Left or Right
implicit def aToEither[A,B](a: A): Either[A, B] = Left(a)
implicit def bToEither[A,B](b: B): Either[A, B] = Right(b)
def f(input: Either[String, Int]) = input match {
case Left(s) => println(s"Hello, $s")
case Right(i) => println(s"You are $i years old")
}
scala> f(10)
You are 10 years old
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment