How to write a custom linear collection in scala

I would like to write a custom linear collection. Something like an expanded list in some specific cases (not for all parameter types).

Scala has a complex collection class hierarchy and I am lost. What the heck should I extend, what methods should I implement?

I found a comprehensible tutorial for a custom implementation: http://daily-scala.blogspot.ru/2010/04/creating-custom-traversable.html .

And I'm looking for similar hints about implementing a custom linear sequence.

+3


source to share


1 answer


This is really not that different from the traverasable implementation. There LinearSeq

are only two abstract methods and three on LinearSeqLike

, which you must extend as well.

However, as is clear from the doc for the latter, it is important to override the following methods so that they have an efficient implementation:



 def isEmpty: Boolean
 def head: A
 def tail: Repr

      

+3


source







All Articles