Это из источника стандартной библиотеки Scala от 2.8.1Scala: Это ошибка в черте LinkedListLike?
/** Append linked list `that` at current position of this linked list
* @return the list after append (this is the list itself if nonempty,
* or list `that` if list this is empty.)
*/
def append(that: This): This = {
@tailrec
def loop(x: This) {
if (x.next.isEmpty) x.next = that
else loop(x.next)
}
if (isEmpty) that
else { loop(repr); repr }
}
/** Insert linked list `that` at current position of this linked list
* @note this linked list must not be empty
*/
def insert(that: This): Unit = {
require(nonEmpty, "insert into empty list")
if (that.nonEmpty) {
next = next.append(that)
}
}
Если это не последняя строка будет next = that.append(next)
? (т. е. поместить остальную часть этого связанного списка в конец списка, который мы вставляем?
Если нет, то почему бы и нет? Код в настоящее время добавляет список, который мы вставляем в конец текущего, то есть в apppend.
Да, это один. 2,8 .1 только, кажется. Может быть, я начинаю чтобы понять эту вещь Скала :) – 2010-12-15 22:44:49