3

I'm trying to work out how all the traits like Seq, Iterable, Traverable, TraversableLike all work together.

I'm slowly getting a bit of a spider web diagram, as I try and draw the relationships in a UML class diagram.

Is there a reason that for example scala.collection.immutable.Seq inherits from scala.collection.generic.GenericTraversableTemplate, even though it inherits that trait from its parent scala.collection.immutable.Iterable?

The collections API seems to be full of duplicated inheritances, which is leading me to think I haven't understood something...

Cheers, Ant

Ant Kutschera
  • 6,257
  • 4
  • 29
  • 40
  • 1
    See http://stackoverflow.com/questions/1722137/scala-2-8-collections-design-tutorial/1724807#1724807 for a start. – huynhjl Feb 23 '12 at 22:29
  • 1
    [This page](http://www.decodified.com/scala/collections-api.xml) has a copy of the diagrams in the answer listed above. I like it better because it's searchable and has links to the appropriate scaladoc pages. – Leif Wickland Feb 24 '12 at 03:04

1 Answers1

3

trait Seq [+A] extends Iterable[A] with Seq[A] with GenericTraversableTemplate[A,Seq] with SeqLike[A, Seq[A]] with Parallelizable[A, ParSeq[A]]

trait Iterable [+A] extends Traversable[A] with Iterable[A] with GenericTraversableTemplate[A,Iterable] with IterableLike[A, Iterable[A]] with Parallelizable[A, ParIterable[A]]

As you can see, Seq and Traversable actually extend GenericTraversableTemplate with different type parameters, so that, for example, method flatten has appropriate return type in each case.

mmmbell
  • 438
  • 2
  • 13