UPD: starting with Kotlin 1.2 the following is available:
The most effective option, creates the least number of intermediate objects:
listOf(1, 2, 3).asSequence().zipWithNext { a, b -> a <= b }.all { it }
A slightly less efficient option:
listOf(1, 2, 3).asSequence().windowed(2).all { (a, b) -> a <= b }
, List(a, b)
.
@Billbucket @AshishChaudhary .
, Kotlin:
:
val a = listOf("a", "b", "c")
a.zip(a.drop(1)).all { (a, b) -> a <= b }
// true
:
a.zip(a.drop(1))
. , .
, . :
a.asSequence().let { it.zip(it.drop(1)).all { (a, b) -> a < b } }
O(N)
( ), .