What are all the things you can do with a collection? Let's think of some use cases:
- First, create a collection object
- Insert an element
- Perform an operation on each element of a collection, which is only possible when you access each element
- Traverse through the collection
- Break it down into parts, perhaps one part with a single first element, and another with the rest of the collection (which are
head
andtail
, obviously) - Randomly seek out a particular element
- Update an element
- Reverse the collection
So, this covers pretty much everything you can do with a collection. The good thing is that if you're sure about the kinds of operations you're going to perform on your collection, you can make a performant program. The bad news is we hardly think about the operations we're going to perform later in programs, unless you're fortunate. But we've got an idea about all the collections and their performance. You may want to refer to the performance characteristics table in Scala's...