What is the basic collection type in Scala?
Asked Answered
S

1

12

Or in other words what is the equivalent of C# IEnumerable<T> in Scala? I thought it is Seq[T], but I already found out, that HashMap does not implement this, so it cannot be true.

So, what is it?

Sufferance answered 12/10, 2011 at 19:5 Comment(1)
HashMap does implement Seq. Maybe you were looking at java.util.HashMap?Cephalonia
E
20

Traversable and Iterable are base traits for scala collections. Actually, Iterable extends Traversable.

From scala api doc for Iterable:

A base trait for iterable collections.

This is a base trait for all Scala collections that define an iterator method to step through one-by-one the collection's elements.

And Traversable:

This is a base trait of all kinds of Scala collections. It implements the behavior common to all collections, in terms of a method foreach.

Here is a nice pics from scala-lang site that represents scala collections hierarchy (mutable and immutable respectively):

enter image description here

Immutable:

enter image description here

Erena answered 12/10, 2011 at 19:14 Comment(2)
Awesome, thank you very much (now I found it using google images :-) scala-lang.org/docu/files/collections-api/collections_1.html .Sufferance
and Traversable extends TraversableOnce (which unites Iterator and Traversable) and TraversableOnce extends GenTraversableOnce (which units the sequential collections and the parallel.)Burks

© 2022 - 2024 — McMap. All rights reserved.