singleOrNull

Common
JVM
JS
Native
1.0
fun <T> Array<out T>.singleOrNull(): T?
fun ByteArray.singleOrNull(): Byte?
fun ShortArray.singleOrNull(): Short?
fun IntArray.singleOrNull(): Int?
fun LongArray.singleOrNull(): Long?
fun FloatArray.singleOrNull(): Float?
fun DoubleArray.singleOrNull(): Double?
fun BooleanArray.singleOrNull(): Boolean?
fun CharArray.singleOrNull(): Char?

Returns single element, or null if the array is empty or has more than one element.

Common
JVM
JS
Native
1.0
inline fun <T> Array<out T>.singleOrNull(
    predicate: (T) -> Boolean
): T?
inline fun ByteArray.singleOrNull(
    predicate: (Byte) -> Boolean
): Byte?
inline fun ShortArray.singleOrNull(
    predicate: (Short) -> Boolean
): Short?
inline fun IntArray.singleOrNull(
    predicate: (Int) -> Boolean
): Int?
inline fun LongArray.singleOrNull(
    predicate: (Long) -> Boolean
): Long?
inline fun FloatArray.singleOrNull(
    predicate: (Float) -> Boolean
): Float?
inline fun DoubleArray.singleOrNull(
    predicate: (Double) -> Boolean
): Double?
inline fun BooleanArray.singleOrNull(
    predicate: (Boolean) -> Boolean
): Boolean?
inline fun CharArray.singleOrNull(
    predicate: (Char) -> Boolean
): Char?
inline fun <T> Iterable<T>.singleOrNull(
    predicate: (T) -> Boolean
): T?

Returns the single element matching the given predicate, or null if element was not found or more than one element was found.

Common
JVM
JS
Native
1.0
fun <T> Iterable<T>.singleOrNull(): T?

Returns single element, or null if the collection is empty or has more than one element.

Common
JVM
JS
Native
1.0
fun <T> List<T>.singleOrNull(): T?

Returns single element, or null if the list is empty or has more than one element.