Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Collections Library Inheritance

Tags:

scala

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

like image 583
Ant Kutschera Avatar asked Dec 19 '25 18:12

Ant Kutschera


1 Answers

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.

like image 115
mmmbell Avatar answered Dec 22 '25 08:12

mmmbell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!