firstThatOrNull

inline fun <T> Iterable<T>.firstThatOrNull(predicate: (index: Int, T) -> Boolean): T?(source)

Returns the first element in this iterable for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This iterable to search in iteration order.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.

Type Parameters

T

The element type of this iterable.


inline fun <T> Array<T>.firstThatOrNull(predicate: (index: Int, T) -> Boolean): T?(source)

Returns the first element in this object array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This object array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.

Type Parameters

T

The element type of this object array.


inline fun ByteArray.firstThatOrNull(predicate: (index: Int, Byte) -> Boolean): Byte?(source)

Returns the first element in this byte array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This byte array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun ShortArray.firstThatOrNull(predicate: (index: Int, Short) -> Boolean): Short?(source)

Returns the first element in this short array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This short array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun IntArray.firstThatOrNull(predicate: (index: Int, Int) -> Boolean): Int?(source)

Returns the first element in this int array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This int array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun LongArray.firstThatOrNull(predicate: (index: Int, Long) -> Boolean): Long?(source)

Returns the first element in this long array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This long array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun FloatArray.firstThatOrNull(predicate: (index: Int, Float) -> Boolean): Float?(source)

Returns the first element in this float array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This float array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun DoubleArray.firstThatOrNull(predicate: (index: Int, Double) -> Boolean): Double?(source)

Returns the first element in this double array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This double array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun BooleanArray.firstThatOrNull(predicate: (index: Int, Boolean) -> Boolean): Boolean?(source)

Returns the first element in this boolean array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This boolean array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.


inline fun CharArray.firstThatOrNull(predicate: (index: Int, Char) -> Boolean): Char?(source)

Returns the first element in this char array for which predicate returns true, or null if none match.

The predicate receives the zero-based index of each element together with the element itself.

Receiver

This char array to search from start to end.

Return

The first matching element, or null if no element satisfies predicate.

Parameters

predicate

Called with the index and each element; should return true for the element to return.