Hi guys I was trying to filter upon a sealed clas...
# getting-started
i
Hi guys I was trying to filter upon a sealed class-specific state but the filter function didn't work. Does anyone know how to do filter against sealed classes state? for example:
Copy code
sealed class States{
object Loading:States()
data Success(val data: String):States()
}

results.filter{
 it.state is States.Success 
}.forEach{ successState ->
println(successState.data) //Error since this still State not Success State
}
j
You can use
filterIsInstance<States.Success>()
instead of a classic
filter
to have the correct type down the line
👍 2
i
Oh, I didn't notice this function. Thanks for your help.
117 Views