Skip to content

Instantly share code, notes, and snippets.

@kiritsuku
Created June 23, 2012 17:07
Show Gist options
  • Select an option

  • Save kiritsuku/2979052 to your computer and use it in GitHub Desktop.

Select an option

Save kiritsuku/2979052 to your computer and use it in GitHub Desktop.
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