Skip to content

Instantly share code, notes, and snippets.

@owainlewis
Created December 16, 2013 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owainlewis/7987494 to your computer and use it in GitHub Desktop.
Save owainlewis/7987494 to your computer and use it in GitHub Desktop.
Functors
// covariant functor
trait Functor[F[_]] {
def fmap[A, B](f: A => B): F[A] => F[B]
}
// contravariant functor
trait Contravariant[F[_]] {
def contramap[A, B](f: B => A): F[A] => F[B]
}
// exponential functors — defines the operation commonly known as xmap. Also known as invariant functors.
// exponential functor
trait Exponential[F[_]] {
def xmap[A, B](f: (A => B, B => A)): F[A] => F[B]
}
// applicative functor1 — defines the operation commonly known as apply or <*>.
// applicative functor (abbreviated)
trait Applicative[F[_]] {
def apply[A, B](f: F[A => B]): F[A] => F[B]
}
// monad2 — defines the operation commonly known as bind, flatMap or =<<.
// monad (abbreviated)
trait Monad[F[_]] {
def flatMap[A, B](f: A => F[B]): F[A] => F[B]
}
// comonad3 — defines the operation commonly known as extend, coflatMap or <<=.
// comonad (abbreviated)
trait Comonad[F[_]] {
def coflatMap[A, B](f: F[A] => B): F[A] => F[B]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment