If you look at IntFunction
it might become clearer: IntFunction<R>
is a FunctionalInterface
. It represents a function that takes an int
and returns a value of type R
.
In this case, the return type R
is also a FunctionalInterface
, namely an IntUnaryOperator
. So the first (outer) function itself returns a function.
In this case: When applied to an int
, curriedAdd
is supposed to return a function that again takes an int
(and returns again int
, because that's what IntUnaryOperator
does).
In functional programming it is common to write the type of a function as param -> return_value
and you see exactly that here. So the type of curriedAdd
is int -> int -> int
(or int -> (int -> int)
if you like that better).
Java 8's lambda syntax goes along with this. To define such a function, you write
a -> b -> a + b
which is very much similar to actual lambda calculus:
λa λb a + b
λb a + b
is a function that takes a single parameter b
and returns a value (the sum). λa λb a + b
is a function that accepts a single parameter a
and returns another function of a single parameter. λa λb a + b
returns λb a + b
with a
set to the parameter value.