🔀 Merge branch 'release/v82'
[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()
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
8
9 fun <T> T?.onNull(block: () -> Unit) = this.also {
10         if (this == null) {
11                 block()
12         }
13 }