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; } public void setOutOfStock(boolean outOfStock) { this.outOfStock = outOfStock; } public Optional<Part> outOfStock(boolean outOfStock) { this.outOfStock ...