W3cubDocs

/Kotlin

all

inline fun <T> Array<out T>.all(
    predicate: (T) -> Boolean
): Boolean
inline fun ByteArray.all(
    predicate: (Byte) -> Boolean
): Boolean
inline fun ShortArray.all(
    predicate: (Short) -> Boolean
): Boolean
inline fun IntArray.all(predicate: (Int) -> Boolean): Boolean
inline fun LongArray.all(
    predicate: (Long) -> Boolean
): Boolean
inline fun FloatArray.all(
    predicate: (Float) -> Boolean
): Boolean
inline fun DoubleArray.all(
    predicate: (Double) -> Boolean
): Boolean
inline fun BooleanArray.all(
    predicate: (Boolean) -> Boolean
): Boolean
inline fun CharArray.all(
    predicate: (Char) -> Boolean
): Boolean
inline fun <T> Iterable<T>.all(
    predicate: (T) -> Boolean
): Boolean

Returns true if all elements match the given predicate.

import kotlin.test.*

fun main(args: Array<String>) {
//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
}
inline fun <K, V> Map<out K, V>.all(
    predicate: (Entry<K, V>) -> Boolean
): Boolean

Returns true if all entries match the given predicate.

import kotlin.test.*

fun main(args: Array<String>) {
//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
}

© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/all.html