Applicative types are Apply types with one extra function, which we define in Fantasy Land as “of“: With “of”, we can take a value, and lift it into the given Applicative. That’s it! In the wild, most Apply types you practically use will also be Applicative.
With an applicative, our values are wrapped in a context, just like Functors:
But our functions are wrapped in a context too!
Applicative functor must know, how to apply a function wrapped in a context to a value wrapped in a context:
See the Pen BVVrvP by SanderV1992 (@sanderv1992) on CodePen.
See the Pen pKKLjO by SanderV1992 (@sanderv1992) on CodePen.
> Just (+3) <*> Just 2
-- Just 5
> [(*2), (+3)] <*> [1, 2, 3]
-- [2, 4, 6, 4, 5, 6]
> (*) <$> Just 5 <*> Just 3
-- Just 15