any
Returns true
if char sequence has at least one character.
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val emptyList = emptyList<Int>()
assertFalse(emptyList.any())
val nonEmptyList = listOf(1, 2, 3)
assertTrue(nonEmptyList.any())
//sampleEnd
}
Returns true
if at least one character matches the given predicate.
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
val isEven: (Int) -> Boolean = { it % 2 == 0 }
val zeroToTen = 0..10
assertTrue(zeroToTen.any { isEven(it) })
assertTrue(zeroToTen.any(isEven))
val odds = zeroToTen.map { it * 2 + 1 }
assertFalse(odds.any { isEven(it) })
val emptyList = emptyList<Int>()
assertFalse(emptyList.any { true })
//sampleEnd
}