Pablo
08/20/2020, 3:24 PMFlow so what I want to do is change the List<Animals> to a Flow<List<Animals>> but then, I'm losing the mappers on my use-case and on my presentation ? Is there any way to keep mapping the values from the data layer? I mean, my dao now returns a Flow<List<Animals>> do I have to change also the repository return to be a Flow<List<Animals>> ? I had a return List<AnimalsMappedToDomain> , but now how can I do that mapper? What would be the flow from repository to presentation using the mappers?bezrukov
08/20/2020, 3:29 PMfun animalFlow(): Flow<List<AnimalsMappedToDomain> = dao.animals.map { animals ->
animals.map { animal ->
animal.mapToDomain()
}
}Pablo
08/20/2020, 3:35 PMEither<Exception,List<AnimalsMappedtoDomain>>Pablo
08/20/2020, 3:38 PMEither and then on my ViewModel I was using the fold to get the Left and Right now that I'm changing to Flow don't know how to tract thisbezrukov
08/20/2020, 3:48 PMPablo
08/20/2020, 3:51 PMbezrukov
08/20/2020, 3:52 PMFlow<T> to Flow<Either<Exception, T>>
fun Flow<T>.handleErrors() = flow {
try {
collect {
emit( // either with element)
}
} catch (e: Exception) {
emit(// either with error)
}
}
Another option is to expose Flow<List<Animal...>> and in VM use .catch operatorPablo
08/20/2020, 4:03 PMPablo
08/20/2020, 4:03 PM