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