Is foreach by-definition guaranteed to iterate the subject collection (if it defines order) sequentially from the very first to the very last (unless accidentally interrupted) element? Aren’t there any compiler optimization switches which can brake it (shuffle the sequence) or plans to make the ordinary foreach parallel in future versions?
Is foreach by-definition guaranteed to iterate the subject collection (if it defines order) sequentially
Share
Foreach is guaranteed to be sequential for sequential collections (that is, the normal hierarchy, or for anything transformed by
.seq). The parallel part of the collections library (which you get from a standard collection via.paror by explicitly using classes fromcollection.parallel) are pretty much guaranteed not to evaluate in order. If you want to be agnostic, you can use theGenXset of traits (e.g.GenSeq); these provide no guarantees either on execution order or that work will be done in parallel.