Functional programming concepts in Java
In this section, we will examine the underlying concept of functions and how they are implemented in Java 8. This includes high-order, first-class, and pure functions.
A first-class function is a function that can be used where other first-class entities can be used. These types of entities include primitive data types and objects. Typically, they can be passed to and returned from functions and methods. In addition, they can be assigned to variables.
A high-order function either takes another function as an argument or returns a function as the return value. Languages that support this type of function are more flexible. They allow a more natural flow and composition of operations. The use of composition is explored in Chapter 3, Function Composition and Fluent Interfaces.
Pure functions have no side effects. The function does not modify nonlocal variables and does not perform I/O.
High-order functions
We will demonstrate the creation and use of the high...