I would still argue that it make some sense. A boo...
# announcements
b
I would still argue that it make some sense. A boolean is said to be
true
or
false
.. not null. So in a way there's less sense in having a
Boolean?
type at all. And if we compare with java the primitive
boolean
has
false
as default value. As per say if it’s not explicitly sat to
true
it is in fact
false
. But I see where you’re coming from and I understand, I was just hoping that something that is used often might be in consideration some syntactic sugaring to get rid of verboseness.
g
I feel like an extension function on
Boolean?
might get you somewhere
Copy code
val Boolean?.falseIfNull: Boolean get() = this ?: false

object Thingy {
    fun isDisposed(): Boolean = TODO()
}

fun test(){

    val sth: Thingy? = Thingy

    if(sth?.isDisposed().falseIfNull){
        //...
    }
}
unfortunately, if you want something resembling language support your probably going to want to hack an operator for yourself
Copy code
operator fun Boolean?.unaryPlus(): Boolean = this ?: false

object Thingy {
    fun isDisposed(): Boolean = TODO()
}

fun test(){

    val sth: Thingy? = Thingy

    if(+sth?.isDisposed()){
        //...
    }
}