Applicative functors are a subset of functors with a few additional requirements imposed on them, thus making them a bit more useful. Similar to functors, applicative functors are computational contexts that are capable of applying a function to the value contained in them. The only difference is that the function to be applied to an applicative functor must itself be wrapped in the context of an applicative functor. Applicative functors also have a different interface of functions associated with them. An applicative functor, in cats
, is manipulated using two functions: fapply
and pure
.
Note
The following examples can be found in src/m_clj/c6/
applicatives.clj
of the book's source code.
The fapply
function from the cats.core
namespace can be called with an applicative functor, as follows:
user> @(cc/fapply (cmm/just inc) (cmm/just 1)) 2
Here, we again use the Maybe
type, this time as an applicative functor. The fapply
function unwraps the inc
...