Add helper for booleans
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / utils / Booleans.kt
diff --git a/src/main/kotlin/net/pterodactylus/sone/utils/Booleans.kt b/src/main/kotlin/net/pterodactylus/sone/utils/Booleans.kt
new file mode 100644 (file)
index 0000000..3202b82
--- /dev/null
@@ -0,0 +1,6 @@
+package net.pterodactylus.sone.utils
+
+/**
+ * Returns the value of [block] if `this` is true, returns `null` otherwise.
+ */
+fun <R> Boolean.ifTrue(block: () -> R): R? = if (this) block() else null