singleOrEmpty

inline fun <T> Iterable<T>.singleOrEmpty(predicate: (T) -> Boolean): T?

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

Throws IllegalArgumentException when multiple elements are matching predicate.

fun <T> Iterable<T>.singleOrEmpty(): T?

Returns single element, or null if the collection is empty. Throws IllegalArgumentException when multiple elements are matching predicate.