W3cubDocs

/Kotlin

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.

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