min
09/17/2026, 7:45 AM?.takeIf { id -> session.classFromId(id)?.isAnnotationClass() == true }
Is there a version of takeIf that lets me return Boolean? or a better idiom to use here to obviate the == true?Youssef Shoaib [MOD]
09/17/2026, 8:10 AM== true is the idiom here.
Dealing with Boolean? Is hard. There's no simple rule as to what null should map to. Sometimes you genuinely want to use == false.
If the expression gets big enough, early returns can be very helpful:
?.takeIf { id ->
val klass = session.classFromId(id) ?: return@takeIf false
klass.isAnnotationClass()
}ggoggam
09/18/2026, 10:45 AM?.takeIf { id ->
session.classFromId(id)?.isAnnotationClass() ?: false
}
or (depending on your logic)
?.takeIf { id ->
session.classFromId(id)?.isAnnotationClass()
} ?: falseYoussef Shoaib [MOD]
09/18/2026, 10:47 AM== pattern being considered more idiomatic for some reason, but hey it's all personal preference at the end of the dayOhiorenua Aigboje
09/19/2026, 12:02 PMephemient
09/19/2026, 8:40 PMIf you need to use a nullablein a conditional statement, useBooleanorif (value == true)checks.if (value == false)
ephemient
09/19/2026, 8:42 PM/!=` because it makes it clear which of the 3 cases you are treating uniquely