When calling takeIf on a value, providing a predicate that checks if the receiver is of a given type does not create a smart cast to that type. For instance, the following code snippets are functionally equivalent, yet in the former, someVal is smart casted, while in the latter, it is not. Is there something I’m missing for why it doesn’t get smart casted in the second snippet?
//Smart cast works for this
val someVal: Any = "Hello"
if (someVal is String) { print(someVal.toLowerCase()) }
//Smart cast doesn't work for this
val someVal: Any = "Hello"
someVal.takeIf { it is String }?.let { print(it.toLowerCase()) }