Java Reference
In-Depth Information
You can now create various transformation pipelines by composing the utility methods, for
example, creating a pipeline that first adds a header, then checks spelling, and finally adds a
footer, as illustrated in figure 3.7 :
Figure 3.7. A transformation pipeline using andThen
Function<String, String> addHeader = Letter::addHeader;
Function<String, String> transformationPipeline
= addHeader.andThen(Letter::checkSpelling)
.andThen(Letter::addFooter);
A second pipeline might be only adding a header and footer without checking for spelling:
Function<String, String> addHeader = Letter::addHeader;
Function<String, String> transformationPipeline
= addHeader.andThen(Letter::addFooter);
3.9. Similar ideas from mathematics
If you feel comfortable with school mathematics, then this section gives another viewpoint of the
idea of lambda expressions and passing around functions. Feel free to just skip it; nothing else
in the topic depends on it, but you may enjoy seeing another perspective.
3.9.1. Integration
Suppose you have a (mathematical, not Java) function f, perhaps defined by
f ( x ) = x + 10
Then, one question that's often asked (at school, in engineering degrees) is that of finding the
area beneath the function when drawn on paper (counting the x-axis as the zero line). For
example, you write
 
Search WWH ::




Custom Search