DEV Community

Discussion on: Streams in Java

 
alainvanhout profile image
Alain Van Hout

Hi Maxime,

Note that the following is specific to JS. It may work similar or quite different in other languages.

To answer your question, try the following code

[1,2,3,4,5]
  .map(x => {
    console.log("A", x);
    return x;
  })
  .map(y => console.log("B", y))

This outputs

A 1
A 2
A 3
A 4
A 5
B 1
B 2
B 3
B 4
B 5

That shows that in JS, a regular array map operation iterates over the entire array before passing it on to the next operation.