stacker - 2 months ago 7x

Java Question

This answer does-java-support-currying defines a

`IntFunction`

`curriedAdd = a -> b -> a + b;`

`IntFunction<IntUnaryOperator> curriedAdd = a -> b -> a + b;`

System.out.println(curriedAdd.apply(4).applyAsInt(5));

IntUnaryOperator adder5 = curriedAdd.apply(5);

System.out.println(adder5.applyAsInt(4));

I read the relevant section 15.27 of the JLS it states:

The production of a lambda expression is

Does this mean that

`a -> b`

`b -> a + b`

Answer

You can expand the expression to make it easier to understand:

```
IntFunction<IntUnaryOperator> curriedAdd = a -> { return b -> a + b; };
```

And indeed you have two lambdas expressions: the inner one which is the unary operator and the outer one which is the function.

Source (Stackoverflow)

Comments