W3cubDocs

/Kotlin

single

Platform and version requirements: JVM (1.0), JS (1.0), 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
@ExperimentalUnsignedTypes fun UIntArray.single(): UInt
@ExperimentalUnsignedTypes fun ULongArray.single(): ULong
@ExperimentalUnsignedTypes fun UByteArray.single(): UByte
@ExperimentalUnsignedTypes fun UShortArray.single(): UShort

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

Platform and version requirements: JVM (1.0), JS (1.0), 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
@ExperimentalUnsignedTypes inline fun UIntArray.single(
    predicate: (UInt) -> Boolean
): UInt
@ExperimentalUnsignedTypes inline fun ULongArray.single(
    predicate: (ULong) -> Boolean
): ULong
@ExperimentalUnsignedTypes inline fun UByteArray.single(
    predicate: (UByte) -> Boolean
): UByte
@ExperimentalUnsignedTypes 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.

Platform and version requirements: JVM (1.0), JS (1.0), 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.

Platform and version requirements: JVM (1.0), JS (1.0), 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.

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/single.html