Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: Purpose Like suffix on traits, e.g. IndexSequenceLike

Tags:

scala

traits

I see names ending with Like for many Scala types. What is the purpose of these traits? Example would be IndexSequenceLike, or QueryLike, etc.

like image 266
user_1357 Avatar asked Jun 11 '14 20:06

user_1357


1 Answers

The Like suffix is used for implementation traits, similar to how Java uses "Impl", for the implementation of an interface.

http://docs.scala-lang.org/overviews/core/architecture-of-scala-collections.html

Scala traits are similar to Java interfaces, only better, because traits can contain function definitions, not just declarations.

The IndexedSeqLike trait is therefore the implementation of an IndexedSeq trait (interface). When added to a class definition, its implementation methods come with it.

This allows code reuse in the Scala library, as well as helping to implement the convention that Iterator should always return the same type.

like image 64
Brent Faust Avatar answered Nov 15 '22 05:11

Brent Faust