Scala.collection
lastmod 2020-10-28created 2020-10-282 edits
Scala collections
Basics
Collections you will use all the time
Lists
A standard linked list.
As in other functional languages, you can build one with cons.
- See also: List API
Sets
Duplicates are not allowed.
- See also: Set API
Sequences (Seq)
Sequences have an order.
Note that what is returned is a List. Seq is a trait. List is a good implementation of Seq. As you can see here, there is a factory object called Seq that creates Lists.
- See also: Seq API
Maps (Map)
Maps store key-value pairs.
- See also: Map API
Hierarchy
The following are all traits. The mutable and immutable packages each contain their own implementations of these traits.
Traversable
Every collection must be traversable. This trait defines the standard function combinators. These combinators are implemented on top of @foreach@. @foreach@ is a method every collection must implement.
Iterable
Returns the iterator() method, which returns an iterator that can loop over the elements.
Sequence (Seq)
An ordered sequence of items.
Set
A collection with no duplicate elements.
Map
A collection that holds key-value pairs.