single

Common
JVM
JS
Native
1.0
fun <T> Array<out T>.single(): T
(source)
fun ByteArray.single(): Byte
(source)
fun ShortArray.single(): Short
(source)
fun IntArray.single(): Int
(source)
fun LongArray.single(): Long
(source)
fun FloatArray.single(): Float
(source)
fun DoubleArray.single(): Double
(source)
fun BooleanArray.single(): Boolean
(source)
fun CharArray.single(): Char
(source)
@ExperimentalUnsignedTypes fun UIntArray.single(): UInt
(source)
@ExperimentalUnsignedTypes fun ULongArray.single(): ULong
(source)
@ExperimentalUnsignedTypes fun UByteArray.single(): UByte
(source)
@ExperimentalUnsignedTypes fun UShortArray.single(): UShort
(source)

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

(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)
@ExperimentalUnsignedTypes inline fun UIntArray.single(
    predicate: (UInt) -> Boolean
): UInt

(source)
@ExperimentalUnsignedTypes inline fun ULongArray.single(
    predicate: (ULong) -> Boolean
): ULong

(source)
@ExperimentalUnsignedTypes inline fun UByteArray.single(
    predicate: (UByte) -> Boolean
): UByte

(source)
@ExperimentalUnsignedTypes inline fun UShortArray.single(
    predicate: (UShort) -> Boolean
): UShort

(source)

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
(source)

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
(source)

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