Last active
May 9, 2020 09:25
-
-
Save zaetrik/7f4922d2aefb7e796f35c3a454f63fde to your computer and use it in GitHub Desktop.
Apply Type Class
This file contains hidden or 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
// 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