June 2018
Beginner
722 pages
18h 47m
English
Most of the functional interfaces in the java.util.function package have default methods that allow us to build a chain (also called a pipe or pipeline) of functions that pass the result of one as the input parameter to another, thus composing a new complex function. For example:
Function<Double, Long> f1 = d -> Double.valueOf(d / 2.).longValue();Function<Long, String> f2 = l -> "Result: " + (l + 1);Function<Double, String> f3 = f1.andThen(f2);System.out.println(f3.apply(4.)); //prints: 3
As you can see from the preceding code, we have created a new f3 function by combining the f1 and f2 functions using the andThen() method. That's the idea behind the methods we are going to explore in this section. First, we express ...
Read now
Unlock full access