Lambda for DoubleFunction

Viewed 84

The following snippet is from https://blogs.oracle.com/javamagazine/quiz-yourself-functional-interfaces-advanced?source=:em:nw:mt::RC_WWMK190726P00001:NSL400004372

DoubleStream ds = DoubleStream.of(1.0, 2.0, 3.0);
DoubleFunction<DoubleUnaryOperator> fun = a -> d -> d + a;
System.out.print(ds.map(fun.apply(1.0)).sum());

In my learning of lambdas I understand things like d -> d+a or even (d, a) -> d+a
but although knowing the effect of the function, I can't figure out the syntax of the above lambda.
Could someone please explain or give a link to some tutorial?
Thank you.

1 Answers
a -> d -> d + a;

is the same as

a -> (d -> d + a);

which is a Function that for a double a returns a Function that for a double d returns the sum of a and d.

For more details on partial application of functions, or turning multi-argument function into multiple single argument functions, see currying.

Related