What is the basic collection type in Scala?

后端 未结 1 1599
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 20:13

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

1条回答
  •  星月不相逢
    2021-02-07 20:52

    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

    0 讨论(0)
提交回复
热议问题