← Back to Kairo Docs|API Reference (Dokka)

singleNullOrThrow

suspend fun <T> Flow<T>.singleNullOrThrow(): T?

Adapted from single and singleOrNull. Returns the single element, or null if the flow is empty. If the flow has more than one element, throws IllegalArgumentException.

This is less surprising than singleOrNull because it doesn't return null when there are multiple items in the flow.


inline suspend fun <T> Flow<T>.singleNullOrThrow(crossinline predicate: (T) -> Boolean): T?

Adapted from single and singleOrNull. Returns the single element matching the given predicate, or null if no elements match. If more than one element matches, throws IllegalArgumentException.

This is less surprising than singleOrNull because it doesn't return null when there are multiple items in the flow.