Using functors
Next, let's take a look at functors. A functor is essentially a value in a container or a computational context. The fmap function must be implemented by a functor. This function applies a supplied function to the value contained in a functor. In object-oriented terminology, a functor can be thought of as a generic type with a single abstract method fmap. In a way, reference types, such as refs and atoms, can be thought of as functors that save results, as a reference type applies a function to its contained value in order to obtain the new value that should be stored in it.
Note
The following examples can be found in src/m_clj/c6/ functors.clj of the book's source code.
The fmap function from the cats.core namespace takes two arguments: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access