forEachOrdered semantics

Brian Goetz brian.goetz at
Mon Oct 7 09:38:09 PDT 2013

Recall that Stream.forEach(action) may perform the action for different 
elements in whatever order, in whatever thread, with whatever 
concurrency it chooses, and forEachOrdered(action) promises to perform 
the action in encounter order.

Working through the specs, I think users are expecting a tail-to-head 
sequencing of actions, and that processing element n 
<i>happens-before</i> processing element n+1?

The real question is: what should happen when you do a .forEachOrdered() 
on an unordered stream.  My first thought was that this was plain old 
forEach.  But, I think this is not what the user will expect; I believe 
they will be reasonably expecting that the action is performed in some 
order, one element at a time.

So I'm inclined to spec that this operates in *some* order, which is the 
encounter order if one exists, and that there is a HB edge between 
successive actions?

More information about the lambda-libs-spec-experts mailing list