single

Common
JVM
JS
Native
1.0
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
fun UIntArray.single(): UInt
fun ULongArray.single(): ULong
fun UByteArray.single(): UByte
fun UShortArray.single(): UShort

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

Common
JVM
JS
Native
1.0
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
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.

Common
JVM
JS
Native
1.0
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.

Common
JVM
JS
Native
1.0
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.