Skip to content

Instantly share code, notes, and snippets.

@nicktelford
Created March 26, 2012 12:19
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 nicktelford/2204734 to your computer and use it in GitHub Desktop.
Save nicktelford/2204734 to your computer and use it in GitHub Desktop.
Implicits for Either? Nasty of helpful?
object Either {
implicit def aToLeft[A, B](value: A): Left[A, B] = Left(value)
implicit def bToRight[A, B](value: B): Right[A, B] = Right(value)
}
import Either._
case class User(id: Either[Long, String])
User(123L)
// res0: User = User(Left(123))
User("123")
// res1: User = User(Right(123))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment