title: How does newly introduced Arrays.parallelPrefix(...) in Java 8 work?
body: <p>I came across <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#parallelPrefix-double:A-java.util.function.DoubleBinaryOperator-" rel="noreferrer">Arrays.parallelPrefix</a> introduced in Java 8.</p>
  
  <p>This overloaded method performs operation on each element of the input array in a cumulative fashion. For e.g. from docs:</p>
  
  <blockquote>
    <p>Cumulates, in parallel, each element of the given array in place,
    using the supplied function. For example if the array initially holds
    [2, 1, 0, 3] and the operation performs addition, then upon return the
    array holds [2, 3, 3, 6]. Parallel prefix computation is usually more
    efficient than sequential loops for large arrays.</p>
  </blockquote>
  
  <p>So, how does Java achieve this task in <code>parallel</code> when the operation on a term is dependent on the operation result on the previous term, and so on?</p>
  
  <p>I tried going through the code myself and they do use <code>ForkJoinTasks</code>, but it's not so straightforward how they would merge result to get the final array.</p>