In Kotlin way, you can use safe call operator ('?') to do stuffs on nullable objects without crash or even making it inside if (obj!=null) block.
So, some object like
if (someObj != null )
someObj.someOperation() //just doing some operation
is the same thing by calling like : someObj?.someOperation().
So, if you want to check emptiness of list without if-else condition, you can use like below (Which you've already done).
storesList?.takeIf { it.isNotEmpty() }?.apply {
// Provides you list if not empty
}
But what about else condition here?
For that, you can use elvis operator to satisfy condition. What this operator do is if left hand-side of operation is null or doesn't satisfy specific condition then take right hand-side of operand.
So, final code should look like:
storesList?.takeIf { it.isNotEmpty() }?.apply {
// Provides you list if not empty
} ?: run {
// Else condition here
}
Explanation: if storesList is empty or null it goes to else part (that is after elvis) otherwise goes to apply block.