Skip to content

Instantly share code, notes, and snippets.

@nuttycom
Created October 2, 2013 21:15
Show Gist options
  • Save nuttycom/6800642 to your computer and use it in GitHub Desktop.
Save nuttycom/6800642 to your computer and use it in GitHub Desktop.
Monad for the right side of Either.
trait Monad[M[_]] {
def pure[A](a: A): M[A]
def flatMap[A, B](f: A => M[B]): M[A] => M[B]
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a)))
}
class EitherRightMonad[L] extends Monad[({type M[R] = Either[L, R]})#M] {
def pure[A](a: A): Either[L, A] = error("todo")
def flatMap[A, B](f: A => Either[L, B]): Either[L, A] => Either[L, B] = error("todo")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment