Scala's parallel collections are a way to provide users with simple and safe tools to perform parallel programming. They come at the expense of reduced generality; however, for a vast number of parallel applications, they will be a simple and sufficient solution. Parallel collections work by providing parallel versions of various Scala collection classes. How that works can be easily seen with an example. First, we import the ParSeq
class:
scala> import scala.collection.parallel.ParSeq import scala.collection.parallel.ParSeq
We then create a list and get it's parallel counterpart. For all collections, this works the same way—by invoking the par
method on the instance of that collection. The par
method simply returns a parallel version of that collection. For example, if invoked on a List
object, it will return the parallel version of List
. The parallel version acts the same as a regular collection of that type, the only difference being that certain...