• 1000 1003 *
fun getTragosFavoritos() = liveData(Dispatchers.IO) {
emit(Resource.Loading())
try{
emit(repo.getTragosFavoritos())
}catch (e: Exception){
emit(Resource.Failure(e))
}
}
Я хочу сделать карту прямо здесь, я пробовал
fun getTragosFavoritos() = liveData(Dispatchers.IO) {
emit(Resource.Loading())
try{
emit(repo.getTragosFavoritos())
}catch (e: Exception){
emit(Resource.Failure(e))
}
}.map {
//But here I need to consume the Resource and I do that in my view, not here
}
Приведенная выше функция возвращает Resource<List<DrinkEntity>>
, но она должна вернуть Resource<List<Drink>>
У меня есть функция расширения, которая уже преобразует один тип списка в другой
fun List<DrinkEntity>.asDrinkList(): MutableList<Drink> = this.map {
Drink(it.tragoId, it.imagen, it.nombre, it.descripcion, it.hasAlcohol)
}.toMutableList()