Add method to throw no null if condition is met
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / utils / Objects.kt
1 package net.pterodactylus.sone.utils
2
3 fun <T> T?.asList() = this?.let(::listOf) ?: emptyList<T>()
4 val Any?.unit get() = Unit
5
6 fun <T> T?.throwOnNullIf(throwCondition: Boolean, exception: () -> Throwable) =
7                 if (this == null && throwCondition) throw exception() else this