https://kotlinlang.org logo
Title
l

Lucien Guimaraes

05/27/2021, 3:21 PM
While working with flow I'm having a type mismatch with the following code:
homeRepository
.requestStuff()
.map { stuff -> HomeState.Success(stuff) }
.catch {
   emit(HomeState.Error.Unknown(it))  <- type mismatch as FlowCollector is waiting for the HomeState.Success type
}
By adding
.filterIsInstance<HomeState>()
before
.catch {...}
it works, but I'm wondering if there is a better way 🤔 Thanks!
a

Adam Powell

05/27/2021, 3:23 PM
.map { stuff -> HomeState.Success(stuff) as HomeState }
💯 1
l

Lucien Guimaraes

05/27/2021, 3:24 PM
don't know why I didn't think of it 🤦 Thanks 👍
The minor issue is AS generate a
No cast needed
on
as HomeState
s

stojan

05/27/2021, 3:28 PM
.map<HomeState> { stuff -> HomeState.Success(stuff) }
should also work