I started looking at Scala collections after realising a need to polish some rough edges in the quest to become a better scala programmer. The scala collections series of blogs are my aim to become better at scala. It has been written from a beginner’s perspective but I hope I would be equally helpful to seasoned programmers.
Scala collections are a vast a topic and there is something for everyone if you know where to start. There are few commonly used collections that are described here and is a good place to start. There are many collections which are not covered and hopefully this blog will give you an idea as to where go and look and how to implement them.
Let’ start – Scala collections have a very well defined & documented hierarchy available here. However, I have taken the liberty to insert a few images from the scala documentation directly here. The diagrams below will provide a sense how vast is the estate of scala collections. If you want to quickly want to have an overview of scala collections these three diagrams are the best source for that quick overview.
Scala collections are contained in a package scala.collection and are of two types
- Immutable – scala.collection.immutable
- Mutable – scala.collection.mutable
Immutable collections are also documented in a hierarchy below
Mutable collections are documented below.
Choosing whether one needs to choose a List, Sequence, Vector or any other collection type is based on the use case. As a developer, performance is an important factor. Hence, performance of the collection should also be taken into consideration. Question is how do I measure performance. Scala documentation to the rescue! here. Please do read this documentation it really clears up how to use scala collections and when and is not at all complicated.
Until next time…..