Created
June 23, 2012 17:07
-
-
Save kiritsuku/2979052 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 X { | |
| class EitherProvidesProjection[A, B](e: Either[A, B]) { | |
| def project[A1](f: A => A1) = e match { | |
| case Left(l) => Left(f(l)).right | |
| case Right(r) => Right(r).right | |
| } | |
| } | |
| implicit def EitherProvidesProjection[A, B](e: Either[A, B]) = new EitherProvidesProjection(e) | |
| for { | |
| a <- Right[String, String]("") project i18n | |
| b <- Left[String, String]("") project i18n | |
| } yield a+b | |
| def i18n(code: String, args: Any*): String = null | |
| def i18n(code: String): String = i18n(code, "") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment