Skip to content

Instantly share code, notes, and snippets.

@globulon
Created February 15, 2012 20:53
Show Gist options
  • Select an option

  • Save globulon/1838933 to your computer and use it in GitHub Desktop.

Select an option

Save globulon/1838933 to your computer and use it in GitHub Desktop.
Monad and Functor definitions
trait Functor[M[_]] {
def map[T,P >: T, U](source: M[T])(f: P => U): M[U];
}
trait Monad[M[_]] {
def apply[T](data: T): M[T]
def flatten[T](m: M[M[T]]): M[T]
final def flatMap [T, P>: T, U](source: M[T])(t: P => M[U])(implicit f: Functor[M]): M[U] = {
flatten(f.map(source)(t))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment