diff --git a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/IfBoolean.kt b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/IfBoolean.kt index b953f423eb6..e6401389c4e 100644 --- a/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/IfBoolean.kt +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/IfBoolean.kt @@ -1,5 +1,31 @@ package dev.inmo.micro_utils.common +inline fun Boolean.letIfTrue(block: () -> T): T? { + return if (this) { + block() + } else { + null + } +} + +inline fun Boolean.letIfFalse(block: () -> T): T? { + return if (this) { + null + } else { + block() + } +} + +inline fun Boolean.alsoIfTrue(block: () -> Unit): Boolean { + letIfTrue(block) + return this +} + +inline fun Boolean.alsoIfFalse(block: () -> Unit): Boolean { + letIfFalse(block) + return this +} + inline fun Boolean.ifTrue(block: () -> T): T? { return if (this) { block()