W3cubDocs

/Kotlin

singleOrNull

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

Returns single element, or null 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>.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?
@ExperimentalUnsignedTypes inline fun UIntArray.singleOrNull(
    predicate: (UInt) -> Boolean
): UInt?
@ExperimentalUnsignedTypes inline fun ULongArray.singleOrNull(
    predicate: (ULong) -> Boolean
): ULong?
@ExperimentalUnsignedTypes inline fun UByteArray.singleOrNull(
    predicate: (UByte) -> Boolean
): UByte?
@ExperimentalUnsignedTypes inline fun UShortArray.singleOrNull(
    predicate: (UShort) -> Boolean
): UShort?

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

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

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

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/single-or-null.html