title: Java Stream API: why the distinction between sequential and parallel execution mode?
body: <p>From the <a href="http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html" rel="noreferrer">Stream javadoc</a>:</p>
  
  <blockquote>
    <p><em>Stream pipelines may execute either sequentially or in parallel. This execution mode is a property of the stream. Streams are created with an initial choice of sequential or parallel execution.</em></p>
  </blockquote>
  
  <p>My assumptions:</p>
  
  <ol>
  <li>There is no functional difference between a sequential/parallel streams. Output is never affected by execution mode.</li>
  <li>A parallel stream is always preferable, given appropriate number of cores and problem size to justify the overhead, due to the performance gains.</li>
  <li>We want to write code once and run anywhere without having to care about the hardware (this is Java, after all).</li>
  </ol>
  
  <p>Assuming these assumptions are valid (nothing wrong with a bit of meta-assumption), <strong>what's the value in having the execution mode exposed in the api?</strong></p>
  
  <p>It seems like you should just be able to declare a <code>Stream</code>, and the choice of sequential/parallel execution should be handled automagically in a layer below, either by library code or the JVM itself as a function of the cores available at runtime, the size of the problem, etc.</p>
  
  <p>Sure, assuming parallel streams also work on a single core machine, perhaps just always using a parallel stream achieves this. But this is really ugly - why have explicit references to parallel streams in my code when it's the default option?</p>
  
  <p>Even if there is a scenario where you'd deliberately want to hard code the use of a sequential stream - why is there not just a sub-interface <code>SequentialStream</code> for that purpose, rather than polluting <code>Stream</code> with an execution mode switch?</p>