Tuples
Scala tuples are used to combine a fixed number of items together. The ultimate target of this grouping is to help in the anonymous function and so that they can be passed around as a whole. The real difference with an array or list is that a tuple can hold objects of different types while maintaining the information of the type of each element, while a collection doesn't and uses, as the type, the common type (for instance, in the previous example, the type of that set would be Set[Any]).
From the computational point of view, Scala tuples are also immutable. In other words, Tuples do use a classes to store elements (for example, Tuple2, Tuple3, Tuple22, and so on).
The following is an example of a tuple holding an integer, a string, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access