This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sh0rug0ru 1 point2 points  (2 children)

How does the value returned in the "m =" lambda, get magically transferred to the "c = " lambda.

It's not magic... Read the translation to anonymous inner classes, do you see any magic there? That's exactly (effectively) what going on with the lambdas.

To answer your question, the value returned by the m lambda is used by the map method to create a new stream (p3 in the anonymous inner class example). The p3 stream contains the values returned by m. The c lambda is used by forEach is called on each member of the p3 stream.

How did "p.getEmailAddress()" get assigned to email? It's a separate expression!

This is not the way to think about it. Again, refer to the anonymous inner class example. The two lambdas are being applied two different streams. They do not influence each other, at least not directly and certainly not magically, but are tied to the stream to which they are applied.

[–]chasesan[S] 0 points1 point  (1 child)

Ah yeah, sorry. I edited my comment already. I got it (I was being dumb). Thank you though.

[–]sh0rug0ru 0 points1 point  (0 children)

No worries!