Created
December 16, 2013 14:10
-
-
Save owainlewis/7987494 to your computer and use it in GitHub Desktop.
Functors
This file contains 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
// 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