Important note about Seq, IndexedSeq, and LinearSeq
As an important note, I use
Seq in the following examples to keep things simple, but in your code you should be more precise and use
LinearSeq where appropriate. As the
Seq class Scaladoc states:
This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.8, “Make the Scala ArrayBuffer Class Your ‘Go To’ Mutable Indexed Sequence”
You want to use a general-purpose, mutable indexed sequence in your Scala applications.
This is an excerpt from the Scala Cookbook. This is Recipe 10.7, “Make the Vector Class Your ‘Go To’ Immutable Sequence.”
You want a fast, general-purpose, immutable, sequential collection type for your Scala applications.
Vector class was introduced in Scala 2.8 and is now considered to be the “go to,” general-purpose immutable sequential data structure.
This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.2.
Scala FAQ: How do I choose a Scala collection class to solve a particular problem?
To being with, there are three main categories of collection classes to choose from:
This is an excerpt from the Scala Cookbook. (This is Recipe 10.1.)
Overview: The Scala collections hierarchy is very rich (both deep and wide), and understanding how it’s organized can be helpful when choosing a collection to solve a problem.
Figure 10-1, which shows the traits from which the
Vector class inherits, demonstrates some of the complexity of the Scala collections hierarchy.