Skip to content

Instantly share code, notes, and snippets.

@mmollaverdi
Created October 27, 2016 17:59
Show Gist options
  • Save mmollaverdi/3769611af75f78ae7e8c483a31778533 to your computer and use it in GitHub Desktop.
Save mmollaverdi/3769611af75f78ae7e8c483a31778533 to your computer and use it in GitHub Desktop.
trait Applicative[F[_]] {
def ap[A, B](ff: F[A => B])(fa: F[A]): F[B]
def pure[A](x: A): F[A]
def map2[A, B, C](fa: F[A], fb: F[B])(f: (A, B) => C): F[C] = {
val fCurried: A => B => C = f.curried
val fbc: F[B => C] = ap[A, (B => C)](pure(fCurried))(fa)
ap[B, C](fbc)(fb)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment