first

fun <T> Array<out T>.first(): T(source)

Returns first element.

Since Kotlin

1.0

Throws

if the array is empty.


inline fun <T> Array<out T>.first(predicate: (T) -> Boolean): T(source)
inline fun ByteArray.first(predicate: (Byte) -> Boolean): Byte(source)
inline fun ShortArray.first(predicate: (Short) -> Boolean): Short(source)
inline fun IntArray.first(predicate: (Int) -> Boolean): Int(source)
inline fun LongArray.first(predicate: (Long) -> Boolean): Long(source)
inline fun FloatArray.first(predicate: (Float) -> Boolean): Float(source)
inline fun DoubleArray.first(predicate: (Double) -> Boolean): Double(source)
inline fun BooleanArray.first(predicate: (Boolean) -> Boolean): Boolean(source)
inline fun CharArray.first(predicate: (Char) -> Boolean): Char(source)
inline fun <T> Iterable<T>.first(predicate: (T) -> Boolean): T(source)

Returns the first element matching the given predicate.

Since Kotlin

1.0

Throws

if no such element is found.


fun <T> Iterable<T>.first(): T(source)

Returns first element.

Since Kotlin

1.0

Throws

if the collection is empty.


fun <T> List<T>.first(): T(source)

Returns first element.

Since Kotlin

1.0

Throws

if the list is empty.


Returns first element.

Since Kotlin

1.3

Throws

if the array is empty.


Returns the first element matching the given predicate.

Since Kotlin

1.3

Throws

if no such element is found.