If you express this as non-shorthand lambda syntax or pre-lambda Java anonymous class syntax it is clearer what is happening…
The original question. Why are two arrows? Simple, there are two functions being defined… The first function is a function-defining-function, the second is the result of that function, which also happens to be function. Each requires an ->
operator to define it.
Non-shorthand
IntFunction<IntUnaryOperator> curriedAdd = (a) -> {
return (b) -> {
return a + b;
};
};
Pre-Lambda before Java 8
IntFunction<IntUnaryOperator> curriedAdd = new IntFunction<IntUnaryOperator>() {
@Override
public IntUnaryOperator apply(final int value) {
IntUnaryOperator op = new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand + value;
}
};
return op;
}
};