34 Set

After reading this lesson, you will be able to

  • Define an unordered group of distinct values called Set
  • Add and remove items from Set
  • Manipulate a set’s elements using the map, flatten, and flatMap methods
  • Chain multiple Set instances using for-comprehension

In the previous unit, you have learned about List and the operations you can perform on it. In this lesson, you’ll discover the collection Set as an immutable representation of a group of elements. Sets and lists have many features in common and similar syntax, with a fundamental difference: the items of a set are unique and have no order. You’ll see how to create a set and add and remove elements from it. You’ll discover how to manipulate its items using the map, flatten, and ...

Get Get Programming with Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.