all
Returns true
if all elements match the given predicate.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
println("zeroToTen.all { isEven(it) } is ${zeroToTen.all { isEven(it) }}") // false
println("zeroToTen.all(isEven) is ${zeroToTen.all(isEven)}") // false
val evens = zeroToTen.map { it * 2 }
println("evens.all { isEven(it) } is ${evens.all { isEven(it) }}") // true
val emptyList = emptyList<Int>()
println("emptyList.all { false } is ${emptyList.all { false }}") // true
//sampleEnd
}
Returns true
if all entries match the given predicate.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
//sampleStart
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
println("zeroToTen.all { isEven(it) } is ${zeroToTen.all { isEven(it) }}") // false
println("zeroToTen.all(isEven) is ${zeroToTen.all(isEven)}") // false
val evens = zeroToTen.map { it * 2 }
println("evens.all { isEven(it) } is ${evens.all { isEven(it) }}") // true
val emptyList = emptyList<Int>()
println("emptyList.all { false } is ${emptyList.all { false }}") // true
//sampleEnd
}
Returns true
if all elements match the given predicate.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
//sampleStart
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
println("zeroToTen.all { isEven(it) } is ${zeroToTen.all { isEven(it) }}") // false
println("zeroToTen.all(isEven) is ${zeroToTen.all(isEven)}") // false
val evens = zeroToTen.map { it * 2 }
println("evens.all { isEven(it) } is ${evens.all { isEven(it) }}") // true
val emptyList = emptyList<Int>()
println("emptyList.all { false } is ${emptyList.all { false }}") // true
//sampleEnd
}