X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FObjects.kt;h=d9ec162e8348b8ecfaf65f9adc231f0f682318be;hb=fbdfcedba2d34ee9a214dd6bb70cc10ed129cbfb;hp=6d1d413ef4486502bc5c3f8b85f2eb329923dbfb;hpb=03cec6a6772c2d836d94864adddaf544cbe9d72f;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/utils/Objects.kt b/src/main/kotlin/net/pterodactylus/sone/utils/Objects.kt index 6d1d413..d9ec162 100644 --- a/src/main/kotlin/net/pterodactylus/sone/utils/Objects.kt +++ b/src/main/kotlin/net/pterodactylus/sone/utils/Objects.kt @@ -5,3 +5,9 @@ val Any?.unit get() = Unit fun T?.throwOnNullIf(throwCondition: Boolean, exception: () -> Throwable) = if (this == null && throwCondition) throw exception() else this + +fun T?.onNull(block: () -> Unit) = this.also { + if (this == null) { + block() + } +}