all

Common
JVM
JS
Native
1.0
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
@ExperimentalUnsignedTypes inline fun UIntArray.all(
    predicate: (UInt) -> Boolean
): Boolean
@ExperimentalUnsignedTypes inline fun ULongArray.all(
    predicate: (ULong) -> Boolean
): Boolean
@ExperimentalUnsignedTypes inline fun UByteArray.all(
    predicate: (UByte) -> Boolean
): Boolean
@ExperimentalUnsignedTypes inline fun UShortArray.all(
    predicate: (UShort) -> 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
}
Common
JVM
JS
Native
1.0
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
}