Collections

A collection is a value that holds other values, and in Scala it is immutable unless the program asks for the other kind: adding an element returns a new collection and leaves the old one usable. The same handful of operations works on every one of them, so a List, a Vector, a Set and a Map are read the same way.

This part goes through the collections a program actually uses, the transformations built from map, flatMap, filter and fold, the grouping and sorting that end a computation, and the lazy forms that do the work only when a value is needed. It closes with the mutable collections, and with the reason the course reaches for them rarely.

6.1 Lists and vectors the list literal, :: and ++, a vector that indexes, and what each one costs Open 6.2 Sets and maps a set without duplicates, a map, get and getOrElse, and a sorted print Open 6.3 Arrays and ranges Array and Array.ofDim, 1 to 10, until, by, and a range as a collection Open 6.4 map, flatMap, filter and fold the four transformations most code is made of, and reduce and collect Open 6.5 groupBy, sorting and splitting groupBy, sortBy and sortWith, minBy, partition and span Open 6.6 Iterators, LazyLists and views a lazy pipeline, an infinite sequence, and when each one is the right tool Open 6.7 Mutable collections ArrayBuffer and a mutable map, and why the course reaches for them rarely Open

Lessons