Returns true
if all elements match the given predicate.
Note that if the sequence contains no elements, the function returns true
because there are no elements in it that do not match the predicate. See a more detailed explanation of this logic concept in "Vacuous truth" article.
The operation is terminal.
Since Kotlin
1.0Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
println("zeroToTen.all { isEven(it) } is ${zeroToTen.all { isEven(it) }}")
println("zeroToTen.all(isEven) is ${zeroToTen.all(isEven)}")
val evens = zeroToTen.map { it * 2 }
println("evens.all { isEven(it) } is ${evens.all { isEven(it) }}")
val emptyList = emptyList<Int>()
println("emptyList.all { false } is ${emptyList.all { false }}")
}
Target: JVMRunning on v.2.1.20