You can use the elvis operator and evaluate another block of code with run { ... }:
data?.let {
// execute this block if not null
} ?: run {
// execute this block if null
}
But this seems not to be quite as readable as a simple if–else statement.
Also, you might find this Q&A useful:
- In Kotlin, what is the idiomatic way to deal with nullable values, referencing or converting them