findLast

Common
JVM
JS
Native
1.0
inline fun <T> Array<out T>.findLast(
    predicate: (T) -> Boolean
): T?

(source)
inline fun ByteArray.findLast(
    predicate: (Byte) -> Boolean
): Byte?

(source)
inline fun ShortArray.findLast(
    predicate: (Short) -> Boolean
): Short?

(source)
inline fun IntArray.findLast(
    predicate: (Int) -> Boolean
): Int?

(source)
inline fun LongArray.findLast(
    predicate: (Long) -> Boolean
): Long?

(source)
inline fun FloatArray.findLast(
    predicate: (Float) -> Boolean
): Float?

(source)
inline fun DoubleArray.findLast(
    predicate: (Double) -> Boolean
): Double?

(source)
inline fun BooleanArray.findLast(
    predicate: (Boolean) -> Boolean
): Boolean?

(source)
inline fun CharArray.findLast(
    predicate: (Char) -> Boolean
): Char?

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

(source)
inline fun <T> List<T>.findLast(
    predicate: (T) -> Boolean
): T?

(source)
@ExperimentalUnsignedTypes inline fun UIntArray.findLast(
    predicate: (UInt) -> Boolean
): UInt?

(source)
@ExperimentalUnsignedTypes inline fun ULongArray.findLast(
    predicate: (ULong) -> Boolean
): ULong?

(source)
@ExperimentalUnsignedTypes inline fun UByteArray.findLast(
    predicate: (UByte) -> Boolean
): UByte?

(source)
@ExperimentalUnsignedTypes inline fun UShortArray.findLast(
    predicate: (UShort) -> Boolean
): UShort?

(source)

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
}