Parallel Collections

If laziness is a road to efficiency, parallelism may be considered a flight to that destination. If two or more tasks can be executed in any sequence without any impact on the correctness of the result, then those tasks may very well be run in parallel. Scala provides a few different ways to achieve that. The easiest of those is parallel processing of elements in a collection.

We work with collections of data all the time. We may need to check the price of several products, update inventories based on the orders fulfilled, or tally up payments for recent transactions. When we have a collection of data to work with, we often use internal iterators like map, filter, and foldLeft (we used a few of these in Chapter 8, Collections ...

Get Pragmatic Scala now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.