Monads

A monad structure can be thought of as a chain of operations wrapped around an object. These operations are executed against an object and return some value. In this sense, monads support function composition.

The chaining sequence allows programmers to create pipelines, a sequence of operations, to solve their problems. In addition, monads allow operations against the contained values without having to extract them.

To illustrate the use of monads, we will be using a Part class as defined here:

public class Part { private int partNumber; private String partName; private boolean outOfStock; public Part(int partNumber, String partName) { this.partNumber = partNumber; this.partName = partName; } public boolean isOutOfStock() { return outOfStock; ...

Get Learning Java Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.