Book Image

Learning Concurrent Programming in Scala

By : Aleksandar Prokopec
5 (1)
Book Image

Learning Concurrent Programming in Scala

5 (1)
By: Aleksandar Prokopec

Overview of this book

Table of Contents (18 chapters)
Learning Concurrent Programming in Scala
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing custom parallel collections


Parallel collections in the Scala standard library are sufficient for most tasks, but in some cases we want to add parallel operations to our own collections. The Java String class does not have a direct parallel counterpart in the parallel collections framework. In this section, we will study how to implement a custom ParString class that supports parallel operations. We will then use our custom parallel collection class in several example programs.

The first step to implementing a custom parallel collection is to extend the correct parallel collection trait. A parallel string is a sequence of characters, so we need to extend the ParSeq trait with the Char type argument. Once a string is created, it can no longer be modified; we say that the string is an immutable collection. For this reason, we extend a subtype of the scala.collection.parallel.ParSeq trait, the ParSeq trait from the scala.collection.parallel.immutable package:

class ParString(val...