What Is Applicative? Basic Theory for Java Developers

Applicative is just another concept similar in meaning and history to Functors and Monads. I have covered these two in my previous articles, and I think it is finally time to start closing this little series about the most commonly known functional abstractions. Besides explaining some details and theory, I will implement a simple Applicative. I will also use Optional, hopefully one last time, to show what advantages Applicatives give us.

The source code for this article is available in GitHub repository.

What Is a Functor? Basic Theory for Java Developers

In general, a Functor is a concept originating from mathematics, to be exact from a part of mathematics called category theory. In my very first article, I described in detail a similar concept known as Monad. Here I want to continue that thread, so I will try to give you some more insight into Functors — what they are, how they work, and what the theory behind them is. I will also implement a simple functor to better understand how they work and why using them may be a clearer solution.

The source code for this article is available in GitHub repository.

Functors in Functional Programming


1. Overview

In this tutorial, we’ll take a look at Functor type class in Cats. The idea of Functor is “something that can be mapped over”, we’ll see what is actually mapped and how. In functional programming, Functors come into play when we have types or values wrapped inside contexts or containers. We don’t have to know any of the implementation details of those contexts or containers themselves.

2. SBT Dependencies

To start, let’s add the Cats library to our dependencies :