find
@ExperimentalUnsignedTypes inline fun ULongArray.find(
predicate: (ULong) -> Boolean
): ULong?
(source)
@ExperimentalUnsignedTypes inline fun UByteArray.find(
predicate: (UByte) -> Boolean
): UByte?
(source)
@ExperimentalUnsignedTypes inline fun UShortArray.find(
predicate: (UShort) -> Boolean
): UShort?
(source)
Returns the first element matching the given predicate, or null
if no such element was found.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val numbers = listOf(1, 2, 3, 4, 5, 6, 7)
val firstOdd = numbers.find { it % 2 != 0 }
val lastEven = numbers.findLast { it % 2 == 0 }
println(firstOdd) // 1
println(lastEven) // 6
//sampleEnd
}