Beautiful World of Monads

Sergiy Yevtushenko
7 min readJul 14, 2020

Practical Introduction to Monads for Java Developers

Let me start with the disclaimer. The explanation below is in no way pretends to be precise or absolutely accurate from Functional Programming's perspective. Instead, I’m focusing on clarity and simplicity of the explanation to let as many Java developers get into this beautiful world.

When I started digging into Functional Programming a few years ago, I’ve quickly discovered that there is an overwhelming amount of information, but very little of it is understandable for the average Java developer with almost exclusively imperative background. These days situation is slowly changing. There are countless articles which explain, for example, basic FP concepts and how they are applicable to Java. Or articles explaining how to use Java streams properly. But Monads still remain out of the focus of these articles. I don’t know why this happens, but I’ll try to fill this gap.

What Is Monad, Anyway?

The Monad is … a design pattern. As simple as that. This design pattern consists of two parts:

  • Monad is a container for some value. For every Monad, there are methods which allow wrap value into Monad.
  • Monad implements “Inversion of Control” for the value contained inside. To achieve this, Monad provides methods which accept functions. These functions take a value of the same type as stored in Monad and return a transformed value. The transformed value is wrapped into the same kind of…

--

--

Sergiy Yevtushenko
Sergiy Yevtushenko

Written by Sergiy Yevtushenko

Writing code for 35+ years and still enjoy it…

Responses (1)