Skip to content

Instantly share code, notes, and snippets.

@chrislewis
Created March 18, 2011 02:35
Show Gist options
  • Select an option

  • Save chrislewis/875529 to your computer and use it in GitHub Desktop.

Select an option

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