I was reading the function composition section from Chap-3 Modern Java in action.
I am unable to understand why I can't compose IntFunctions. Am I making a silly mistake or is there any design decision behind this ?
Here is my code with error in comments
package mja;
import java.util.function.Function;
import java.util.function.IntFunction;
public class AppTest2 {
public static void main(String[] args) {
IntFunction<Integer> plusOne = x -> x+1;
IntFunction<Integer> square = x -> (int) Math.pow(x,2);
// Compiler can't find method andThen in IntFunction and not allowing to compile
IntFunction<Integer> incrementThenSquare = plusOne.andThen(square);
int result = incrementThenSquare.apply(1);
Function<Integer, Integer> plusOne2 = x -> x + 1;
Function<Integer, Integer> square2 = x -> (int) Math.pow(x,2);
//Below works perfectly
Function<Integer, Integer> incrementThenSquare2 = plusOne2.andThen(square2);
int result2 = incrementThenSquare2.apply(1);
}
}