currently learning android development (Kotlin).
i wonder if it's a correct usage of let function.
viewModelScope.launch(Dispatchers.IO) {
val response = RetrofitHelper.getRealEstateService().getRealEstateModel()
response.body()?.let {
if(response.isSuccessful){
val data = response.body()
_data.emit(data?.content?: emptyList())
}
}
}
previously i was checking if the value is null in a normal way like this:
if(response.isSuccessful && response.body() != null){
val data = response.body()
_data.emit(data?.content?: emptyList())
}
so i just changed null check with let function.
Thanks!