title: How can I perform operations in JavaScript just like we do pipeline of operations in Java streams?
body: <p>In Java 8 using streams when I chain methods one after the another the execution of operations are performed in pipelined manner.</p>
  
  <p>Example:</p>
  
  <pre><code>List&lt;Integer&gt; nums = Arrays.asList(1,2,3,4,5,6);    
  nums.stream().map(x-&gt;{
      x = x * x;
      System.out.println("map1="+x);
      return x;
  }).map(x-&gt;{
      x = x * 3;
      System.out.println("map2="+x);
      return x;
  }).forEach(x-&gt; System.out.println("forEach="+x));
  </code></pre>
  
  <p>Output:-</p>
  
  <pre><code>map1=1
  map2=3
  forEach=3
  map1=4
  map2=12
  forEach=12
  map1=9
  map2=27
  forEach=27
  map1=16
  map2=48
  forEach=48
  map1=25
  map2=75
  forEach=75
  map1=36
  map2=108
  forEach=108
  </code></pre>
  
  <p>But when I tried similarly in javascript.The result is different.As in javascript first operation gets completed and then second operation is performed.Example:-</p>
  
  <pre><code>var nums = [1,2,3,4,5,6 ];
  nums.map(x =&gt; {
    x = (x * x);
    console.log('map1='+x);
    return x;})
    .map(x =&gt; {
    x = x * 3;
    console.log('map2='+x);
    return x;})
    .forEach(x=&gt; console.log('forEach='+x));
  </code></pre>
  
  <p>Output:-</p>
  
  <pre><code> map1=1
   map1=4
   map1=9
   map1=16
   map1=25
   map1=36
   map2=3
   map2=12
   map2=27
   map2=48
   map2=75
   map2=108
   forEach=3
   forEach=12
   forEach=27
   forEach=48
   forEach=75
   forEach=108
  </code></pre>
  
  <p>Is there any way in JavaScript to make it performs operations in a pipeline manner, and I get output as in the Java program?</p>
  
  <p><a href="https://stackoverflow.com/questions/43408033/javascript-equivalents-for-java-streams-api">This question ask only how to collect like in JavaScript but not how internal working changes for same type of methods</a>.</p>