Created
March 18, 2011 02:35
-
-
Save chrislewis/875529 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
| class RichEither[L, R](val either: Either[L, R]) { | |
| def map[RR](f: R => RR): Either[L, RR] = either match { | |
| case Left(l) => Left(l) | |
| case Right(r) => Right(f(r)) | |
| } | |
| def flatMap[RR](f: R => Either[L, RR]): Either[L, RR] = either match { | |
| case Left(l) => Left(l) | |
| case Right(r) => f(r) | |
| } | |
| def >>=[RR](f: R => Either[L, RR]) = flatMap(f) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment