Applicative functors
An applicative functor is a type of functor that allows for the application of a function encapsulated within a functor to a value that is also wrapped within a functor. This concept translates into enabling operations that can gracefully handle multiple layers of computational contexts, such as error handling or asynchronous operations.
While functors allow us to apply a function to a wrapped value, applicative functors extend this capability by enabling the application of functions that are themselves wrapped in a context. This distinction is crucial for operations where the function application itself may result in a computational context, such as failure, delay, or uncertainty. Let’s look at the difference using the book publishing system example.
Consider a function that calculates royalties based on book sales and another function that adjusts these royalties based on market conditions. Both functions might fail due to various reasons, and their...