I see names ending with Like
for many Scala types. What is the purpose of these traits?
Example would be IndexSequenceLike
, or QueryLike
, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With