single

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

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

Since Kotlin

1.0

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

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

Since Kotlin

1.0

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

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

Since Kotlin

1.0

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

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

Since Kotlin

1.0