all

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

Returns true if all elements match the given predicate.

Note that if the array 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.

Since Kotlin

1.0

Samples

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
}

inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean(source)

Returns true if all elements match the given predicate.

Note that if the collection 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.

Since Kotlin

1.0

Samples

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
}

inline fun <K, V> Map<out K, V>.all(predicate: (Map.Entry<K, V>) -> Boolean): Boolean(source)

Returns true if all entries match the given predicate.

Note that if the map contains no entries, the function returns true because there are no entries in it that do not match the predicate. See a more detailed explanation of this logic concept in "Vacuous truth" article.

Since Kotlin

1.0

Samples

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.

Note that if the array 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.

Since Kotlin

1.3

Samples

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
}