2

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 Answer 1

6
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.