Skip to content

Instantly share code, notes, and snippets.

@zaetrik
Last active May 9, 2020 09:25
Show Gist options
  • Save zaetrik/7f4922d2aefb7e796f35c3a454f63fde to your computer and use it in GitHub Desktop.
Save zaetrik/7f4922d2aefb7e796f35c3a454f63fde to your computer and use it in GitHub Desktop.
Apply Type Class
// Apply extends the Functor type class
// the `ap` method is able to unpack a function (a: A) => B that is wrapped inside a Functor instance
// and then `ap` uses `map` with the unpacked function to apply the function to another Functor
interface Apply<F> extends Functor<F> {
ap: <A, B>(fab: F<(a: A) => B>, fa: F<A>) => F<B>
}
// Under the hood `ap` looks something like this (where `apply` is the general Apply constructor):
// ap: (fab: F<(a: A) => B>, fa) => apply.map(fa, fab.value)
// we take out the function wrapped inside fab and apply it to fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment