Chapter 3. Function Composition and Fluent Interfaces
Having discussed the nature of functions in Java 8, we will now focus on the various ways in which functions can be composed. By compose, we mean how they can be combined in interesting and powerful ways. These techniques include basic function composition and the use of fluent interfaces.
Function composition is concerned with combining two functions to form a third one. Using the output of one function as the input to another one is a common practice. By combining two such functions, we are able to create more complex functions, which can be reused.
We will examine the basic approach for composing functions and then move on to the use of the Function
interface and its compose
and andThen
methods. These methods make it easier to compose functions and use them.
We will also cover the topic of fluent interfaces. This programming style is frequently associated with functional programming languages. Java has used method chaining...