我知道=>操作员意味着E.g Int =>布尔值,但在Trait定义中,我没有看到任何正确的操作数。什么" self:Repr =>"意思?我只能部分填补它。自我是变种?接受输入Repr并返回什么的函数?
trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr] {
self: Repr =>
override protected[this] def thisCollection: LinearSeq[A] = this.asInstanceOf[LinearSeq[A]]
override protected[this] def toCollection(repr: Repr): LinearSeq[A] = repr.asInstanceOf[LinearSeq[A]]
def seq: LinearSeq[A]
override def hashCode()= scala.util.hashing.MurmurHash3.seqHash(seq) // TODO - can we get faster via "linearSeqHash" ?
override /*IterableLike*/
def iterator: Iterator[A] = new AbstractIterator[A] {
var these = self
def hasNext: Boolean = !these.isEmpty
def next(): A =
if (hasNext) {
val result = these.head; these = these.tail; result
} else Iterator.empty.next()
override def toList: List[A] = {
/* Have to clear `these` so the iterator is exhausted like
* it would be without the optimization.
*
* Calling "newBuilder.result()" in toList method
* prevents original seq from garbage collection,
* so we use these.take(0) here.
*
* Check SI-8924 for details
*/
val xs = these.toList
these = these.take(0)
xs
}
}