first

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

Returns the first element, throwing NoSuchElementException when empty.

Reads only the first element. A stored null is returned normally for nullable types. Exceptions from iteration propagate to the caller.

Receiver

elements to visit in their iteration order.

Return

the first element in iteration order.

See also

Throws

if this iterable is empty.


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

Returns the first matching element, throwing NoSuchElementException when no element matches.

Stops at the first match. A matching null is returned normally for nullable types. Exceptions from iteration or the callback propagate to the caller. The inline callback supports non-local returns.

Receiver

elements to visit in their iteration order.

Return

the first accepted element.

Parameters

predicate

test returning true to select an element.

See also

Throws

if empty or no element matches.