inline fun <T> Array<out T>.findLast( predicate: (T) -> Boolean ): T?
inline fun ByteArray.findLast( predicate: (Byte) -> Boolean ): Byte?
inline fun ShortArray.findLast( predicate: (Short) -> Boolean ): Short?
inline fun IntArray.findLast( predicate: (Int) -> Boolean ): Int?
inline fun LongArray.findLast( predicate: (Long) -> Boolean ): Long?
inline fun FloatArray.findLast( predicate: (Float) -> Boolean ): Float?
inline fun DoubleArray.findLast( predicate: (Double) -> Boolean ): Double?
inline fun BooleanArray.findLast( predicate: (Boolean) -> Boolean ): Boolean?
inline fun CharArray.findLast( predicate: (Char) -> Boolean ): Char?
inline fun <T> Iterable<T>.findLast( predicate: (T) -> Boolean ): T?
inline fun <T> List<T>.findLast( predicate: (T) -> Boolean ): T?
@ExperimentalUnsignedTypes inline fun UIntArray.findLast( predicate: (UInt) -> Boolean ): UInt?
@ExperimentalUnsignedTypes inline fun ULongArray.findLast( predicate: (ULong) -> Boolean ): ULong?
@ExperimentalUnsignedTypes inline fun UByteArray.findLast( predicate: (UByte) -> Boolean ): UByte?
@ExperimentalUnsignedTypes inline fun UShortArray.findLast( predicate: (UShort) -> Boolean ): UShort?
Returns the last 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
}
© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/find-last.html