Created
March 26, 2012 12:19
-
-
Save nicktelford/2204734 to your computer and use it in GitHub Desktop.
Implicits for Either? Nasty of helpful?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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