::とか:::の件。
ソースコードをダウンロードしたら、疑問は氷解した。
Listに、::ってcase classが定義されていた。
@SerialVersionUID(0L - 8476791151983527571L) final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extends List[B] { def head : B = hd def tail : List[B] = tl override def isEmpty: Boolean = false import java.io._ private def writeObject(out: ObjectOutputStream) { var xs: List[B] = this while (!xs.isEmpty) { out.writeObject(xs.head); xs = xs.tail } out.writeObject(ListSerializeEnd) } private def readObject(in: ObjectInputStream) { hd = in.readObject.asInstanceOf[B] assert(hd != ListSerializeEnd) var current: ::[B] = this while (true) in.readObject match { case ListSerializeEnd => current.tl = Nil return case a : Any => val list : ::[B] = new ::(a.asInstanceOf[B], Nil) current.tl = list current = list } } }
ええと、beginner's guide とかにあったcase classの項目をどうやら斜め読みしていた…と言う事が判明。
動作を正確に理解出来ませぬ。もっかい読む。
後、:::ってメソッドも定義されている。
こっちは、簡単に理解できた。
def :::[B >: A](prefix: List[B]): List[B] = if (isEmpty) prefix else { val b = new ListBuffer[B] var those = prefix while (!those.isEmpty) { b += those.head those = those.tail } b.prependToList(this) }