June 2018
Beginner
722 pages
18h 47m
English
We can use the andThen(Function after) default method of the Function interface. We have already created the Function<Integer, Double> createMultiplyBy() method:
Function<Integer, Double> createMultiplyBy(double num){ Function<Integer, Double> func = new Function<Integer, Double>(){ public Double apply(Integer i){ return i * num; } }; return func;
We can also write another method that creates a subtracting function with the Double input type, so we can chain it to the multiplying function:
private static Function<Double, Long> createSubtractInt(int num){ Function<Double, Long> func = new Function<Double, Long>(){ public Long apply(Double dbl){ return Math.round(dbl - num); } }; return func;}
Now we can write the following ...
Read now
Unlock full access