From da692ccfc337ab27a458e4ce0b4a2b819cd49de7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 19 Jan 2023 20:21:35 +0600 Subject: [PATCH] add ifTrue/ifFalse --- .../dev/inmo/micro_utils/common/IfBoolean.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 common/src/commonMain/kotlin/dev/inmo/micro_utils/common/IfBoolean.kt 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 new file mode 100644 index 00000000000..b953f423eb6 --- /dev/null +++ b/common/src/commonMain/kotlin/dev/inmo/micro_utils/common/IfBoolean.kt @@ -0,0 +1,17 @@ +package dev.inmo.micro_utils.common + +inline fun Boolean.ifTrue(block: () -> T): T? { + return if (this) { + block() + } else { + null + } +} + +inline fun Boolean.ifFalse(block: () -> T): T? { + return if (this) { + null + } else { + block() + } +}