single

fun <T> Array<out T>.single(): T
fun ByteArray.single(): Byte
fun ShortArray.single(): Short
fun IntArray.single(): Int
fun LongArray.single(): Long
fun FloatArray.single(): Float
fun DoubleArray.single(): Double
fun BooleanArray.single(): Boolean
fun CharArray.single(): Char

Returns the single element, or throws an exception if the array is empty or has more than one element.


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

Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element.


fun <T> Iterable<T>.single(): T

Returns the single element, or throws an exception if the collection is empty or has more than one element.


fun <T> List<T>.single(): T

Returns the single element, or throws an exception if the list is empty or has more than one element.


inline fun UIntArray.single(): UInt
inline fun ULongArray.single(): ULong
inline fun UByteArray.single(): UByte
inline fun UShortArray.single(): UShort

Returns the single element, or throws an exception if the array is empty or has more than one element.

Since Kotlin

1.3

inline fun UIntArray.single(predicate: (UInt) -> Boolean): UInt
inline fun ULongArray.single(predicate: (ULong) -> Boolean): ULong
inline fun UByteArray.single(predicate: (UByte) -> Boolean): UByte
inline fun UShortArray.single(predicate: (UShort) -> Boolean): UShort

Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element.

Since Kotlin

1.3