single

fun single(): T

Returns the first element, or throws an exception if the list length is not 1.

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

返回第一个元素,如果列表长度不为 1,则抛出异常。


fun single(predicate: (T) -> Boolean): T

Returns the first element matching the given predicate, or throws an exception if no such element was found.

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

返回与给定 predicate 匹配的第一个元素,如果未找到此类元素,则抛出异常。