The Scala List class as an immutable, linear, linked-list class. It’s very efficient when it makes sense for your algorithms to (a) prepend all new elements, (b) work with it in terms of its head and tail elements, and (c) use functional methods that traverse the list from beginning to end, such as
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:
To append or prepend one or more elements to a
Seq, use these methods:
As a brief note about the Linux/Unix
sed command, today I learned how to append multiple lines of text to an HTML (or XML) file on macOS. The short answer is that I created a
sed commands file named changes.sed with these contents:
Here’s a short article on dzone.com that explains why you might not need to use
StringBuilder in Java any more.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.22, “How to Merge Scala Sequential Collections”
You want to join two sequences into one sequence, either keeping all of the original elements, finding the elements that are common to both collections, or finding the difference between the two sequences.
There are a variety of solutions to this problem, depending on your needs:
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.