5 ms·
my point is that this style of writing is pervasive within the scala world, including the official api. and it's not just the list class. look at the base xml
by adabsurdo 15y ago
my point is that this style of writing is pervasive within the scala world, including the official api. and it's not just the list class. look at the base xml class, NodeSeq:
http://www.scala-lang.org/api/rc/scala/xml/NodeSeq.html http://www.scala-lang.org/api/rc/scala/xml/NodeSeq.html
- kikibobo69 15y agoThe xml stuff is more the exception than the rule. They've moved away from that approach. Whether to keep it at all has been discussed quite a bit. It would be more fair to look at the newer code in the collection framework to paint what is considered "best practice" by the creators of Scala.
- soc88 15y ago??? These are the same methods. It is common in languages with inheritance that classes implementing the same types have pretty much the same methods available ...
- zohebv 15y agoThese operators such as ++ (concatenation) etc are uniformly available in all collections. It has inherited these operators from base sequence classes/traits specifically TraversableLike. http://www.scala-lang.org/api/rc/scala/collection/TraversableLike.html http://www.scala-lang.org/api/rc/scala/collection/Traversabl... If you write a fancy skiplist and add a TraversableLike trait you will get these operators and the associated methods for free! Check the source code for NodeSeq. https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_RC4/src//library/scala/xml/NodeSeq.scala#L1 https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_... It does not implement any of these operators. It just inherits some features extends immutable.Seq[Node] with SeqLike[Node, NodeSeq] with Equality provides an equality operator and a builder and gets all the other collection operators for free. These operators have the same semantics and implementation across all collection classes unless you specifically override them.