Skip to content

Instantly share code, notes, and snippets.

@wennergr
Last active March 21, 2018 15:29
Show Gist options
  • Save wennergr/9ca09ebfa9ea53705d74294dc9ad6170 to your computer and use it in GitHub Desktop.
Save wennergr/9ca09ebfa9ea53705d74294dc9ad6170 to your computer and use it in GitHub Desktop.
Applicative with map2
trait Applicative[F[_]] extends Functor[F] {
def pure[A](x: A): F[A]
def ap[A, B](ff: F[A => B])(fa: F[A]): F[B]
def map2[A, B, Z](fa: F[A], fb: F[B])(f: (A, B) => Z): F[Z] =
ap(map(fa)(a => (b: B) => f(a,b)))(fb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment