Hideout/src/main/kotlin/dev/usbharu/hideout/util/CollectionUtil.kt

14 lines
312 B
Kotlin

package dev.usbharu.hideout.util
class CollectionUtil
fun <T> Iterable<T>.singleOr(block: (e: RuntimeException) -> Throwable): T {
return try {
this.single()
} catch (e: NoSuchElementException) {
throw block(e)
} catch (e: IllegalArgumentException) {
throw block(e)
}
}