Will Scala's parallel collections guarantee ordering?

落花浮王杯 提交于 2019-12-03 22:29:45

Yes, but the function itself is executed without any particular order.

List(1,2,3).par foreach print // could print out 213

The parallel collections maintain all of the contracts of their non-parallel equivalents.

On collections in which a map operation preserves order, such as List, order will be preserved by the parallel map as well. On collections in which map does not preserve order, such as Set, order will not be preserved in the parallel version.

With unordered collections, there is no guarantee that the result of a parallel operation will even have the same traversal order as its non-parallel equivalent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!