Is foreach by-definition guaranteed to iterate the subject collection sequentially in Scala?
- 阅读更多 关于 Is foreach by-definition guaranteed to iterate the subject collection sequentially in Scala?
问题 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? 回答1: Foreach is guaranteed to be sequential for sequential collections (that is, the normal hierarchy, or for anything transformed by .seq ). The parallel