Scala's MapLike, ListLike, SeqLike, etc how does each compare to Map, List, Seq?

笑着哭i 提交于 2019-12-03 09:57:32

The best source for these details is Martin Odersky and Lex Spoon's "What's New in Scala 2.8: The Architecture of Scala Collections":

The Scala collection library avoids code duplication and achieves the "same-result-type" principle by using generic builders and traversals over collections in so-called implementation traits. These traits are named with a Like suffix; for instance, IndexedSeqLike is the implementation trait for IndexedSeq, and similarly, TraversableLike is the implementation trait for Traversable. Collection classes such as Traversable or IndexedSeq inherit all their concrete method implementations from these traits. Implementation traits have two type parameters instead of one for normal collections. They parameterize not only over the collection's element type, but also over the collection's representation type, i.e., the type of the underlying collection, such as Seq[I] or List[T]...

The whole article is extremely useful if you want to integrate your own collection classes with the Collections API, or if you just want a deeper understanding of how the library works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!