singleOrNull

fun singleOrNull(): T?

Returns the first element, or null if the list length is not 1.

----------------

返回第一个元素,如果列表长度不为 1,则返回 null


fun singleOrNull(predicate: (T) -> Boolean): T?

Returns the first element matching the given predicate, or null if no such element was found.

----------------

返回与给定 predicate 匹配的第一个元素,如果未找到此类元素,则返回 null