While working with flow I'm having a type mismatch...
# coroutines
l
While working with flow I'm having a type mismatch with the following code:
Copy 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
.map { stuff -> HomeState.Success(stuff) as HomeState }
💯 1
l
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
.map<HomeState> { stuff -> HomeState.Success(stuff) }
should also work