Java Reference
In-Depth Information
a natural way using a declarative style. Using streams, you were able to chain several operations
together to express a complicated query. These features are what characterize functional
programming languages; we look at them more carefully under the guise of combinators in the
next chapter, in section 14.5 .
To make things tangible and connect them with the new features in Java 8, we now concretely
define the idea of functional programming and its representation in Java. What we'd like to
impart is that by using functional-programming style, you can write serious programs without
relying on side effects.
13.2. What's functional programming?
The oversimplistic answer to “What is functional programming?” is “programming using
functions.” So what's a function?
It's easy to imagine a method taking an int and a double as arguments and producing a
double—and also having the side effect of counting the number of times it has been called by
updating a mutable variable, as illustrated in figure 13.2 .
Figure 13.2. A function with side effects
But in the context of functional programming a function corresponds to a mathematical
function: it takes zero or more arguments, gives one or more results, and has no side effects.
You can see it as a black box, which takes some inputs and produces some outputs, as illustrated
in figure 13.3 .
 
Search WWH ::




Custom Search