AL
Size: a a a
AL
AA
/**
* Returns a view of the portion of this list between the specified
* <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive. (If
* <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is
* empty.) The returned list is backed by this list, so non-structural
* changes in the returned list are reflected in this list, and vice-versa.
* The returned list supports all of the optional list operations supported
* by this list.<p>
AA
* Returns a view of the portion of this list between the specified [fromIndex] (inclusive) and [toIndex] (exclusive).
* The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.
*
* Structural changes in the base list make the behavior of the view undefined.
AA
AM
fun <T> List<T>.tail(): List<T> = subList(1, size)
x :: xs
типичный для ФП, будет копирование делать.AA
x :: xs
типичный для ФП, будет копирование делать.AL
x :: xs
типичный для ФП, будет копирование делать.AM
AM
AL
L
AA
fun <T> List<T>.tail(): List<T> = subList(1, size)
fun <T> List<T>.headTail(): Pair<T, List<T>> = first() to tail()
val xs = listOf(1, 2)
val (h, t) = xs.headTail()
L
fun <T> List<T>.tail(): List<T> = subList(1, size)
fun <T> List<T>.headTail(): Pair<T, List<T>> = first() to tail()
val xs = listOf(1, 2)
val (h, t) = xs.headTail()
L
fun <T> List<T>.tail(): List<T> = subList(1, size)
fun <T> List<T>.headTail(): Pair<T, List<T>> = first() to tail()
val xs = listOf(1, 2)
val (h, t) = xs.headTail()
AA
ps.zip(ps.tail).count { case (a, b) => a > b }Котлин:
xs zip xs.subList(1, xs.size).count { (a, b) -> a - b }
Как это второе грамотно подхинтовать от красноты?tail
как val <T> List<T>.tail: List<T> get() = subList(1, size)
, то на Котлин код будет выглядеть так:xs.zip(xs.tail).count { (a, b) -> a > b }
AV
QH
AN
AV
AV