X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FObjects.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FObjects.kt;h=d9ec162e8348b8ecfaf65f9adc231f0f682318be;hp=6d1d413ef4486502bc5c3f8b85f2eb329923dbfb;hb=054d9c07efed3c70c9ef12b3d996f69f1080f4b3;hpb=a252a5d76e8ff8e89da3277a8e9472a499b3bc2b 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() + } +}