If I have a nullable Boolean b, I can do the following comparison in Java:
Boolean b = ...;
if (b != null && b) {
/* Do something */
first, add the custom inline function below:
inline fun Boolean?.ifTrue(block: Boolean.() -> Unit): Boolean? {
if (this == true) {
block()
}
return this
}
inline fun Boolean?.ifFalse(block: Boolean?.() -> Unit): Boolean? {
if (null == this || !this) {
block()
}
return this
}
then you can write code like this:
val b: Boolean? = ...
b.ifTrue {
/* Do something in true case */
}
//or
b.ifFalse {
/* Do something else in false case */
}