any

fun <T> Sequence<T>.any(): Boolean

Returns true if sequence has at least one element.

The operation is terminal.

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
}

inline fun <T> Sequence<T>.any(predicate: (T) -> Boolean): Boolean

Returns true if at least one element matches the given predicate.

The operation is terminal.

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
}