Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Last active September 29, 2015 00:37
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 manjuraj/5982372066e70692fea6 to your computer and use it in GitHub Desktop.
Save manjuraj/5982372066e70692fea6 to your computer and use it in GitHub Desktop.
scalaz type constructors
//
// Foldable
// - fold a data structure
// - usually, fold F[A] given a Monoid[A]
//
trait Foldable[F[_]] { self =>
def foldRight[A, B](fa: F[A], z: => B)(f: (A, => B) => B): B
def foldLeft[A, B](fa: F[A], z: B)(f: (B, A) => B): B = {
def foldMap[A,B](fa: F[A])(f: A => B)(implicit F: Monoid[B]): B
...
}
//
// Functor
// - map lifts a function f into functor F and applies it
// to the value within functor F i.e. F[A]
//
trait Functor[F[_]] extends InvariantFunctor[F] { self =>
def map[A, B](fa: F[A])(f: A => B): F[B]
...
}
//
// Apply
// - ap takes a functor that that has a function in it and another
// functor and extracts that function from the first functor and
// then maps it over the second one
//
trait Apply[F[_]] extends Functor[F] { self =>
def ap[A, B](fa: => F[A])(f: => F[A => B]): F[B]
...
}
//
// Applicative
//
trait Applicative[F[_]] extends Apply[F] { self =>
def point[A](a: => A): F[A]
final def pure[A](a: => A): F[A] = point(a)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment