mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-14 02:50:25 +00:00
add alsoIfTrue/alsoIfFalse/letIfTrue/letIfFalse
This commit is contained in:
@@ -1,5 +1,31 @@
|
|||||||
package dev.inmo.micro_utils.common
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
inline fun <T> Boolean.letIfTrue(block: () -> T): T? {
|
||||||
|
return if (this) {
|
||||||
|
block()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> 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 <T> Boolean.ifTrue(block: () -> T): T? {
|
inline fun <T> Boolean.ifTrue(block: () -> T): T? {
|
||||||
return if (this) {
|
return if (this) {
|
||||||
block()
|
block()
|
||||||
|
|||||||
Reference in New Issue
Block a user