Applicative


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: value and context

But our functions are wrapped in a context too! function and context

Applicative functor must know, how to apply a function wrapped in a context to a value wrapped in a context: applicative

Graphic

graph LR; A[Functor] --> B[Apply] B --> C[Applicative]

Example (JavaScript):

See the Pen BVVrvP by SanderV1992 (@sanderv1992) on CodePen.

See the Pen pKKLjO by SanderV1992 (@sanderv1992) on CodePen.

Example (Haskell):

> Just (+3) <*> Just 2
-- Just 5
> [(*2), (+3)] <*> [1, 2, 3]
-- [2, 4, 6, 4, 5, 6]
> (*) <$> Just 5 <*> Just 3
-- Just 15

Read More: