Vivek Modi
06/09/2022, 3:03 PMMutableStateFlow
in my project. When we initialise the MutableStateFlow
object we need to give default value.
val topics = MutableStateFlow<List<String>>(emptyList())
when I collect this value
[null, "Hello", "world"]
I want to pass this list in adapter
. So is there a way we can remove the null object before passing in adapter or Is there any better way ?
viewModel.topics.collect { topicsList ->
println(topicsList) // [null, "Hello", "world"]
adapter.submitList(topicsList)
}
Desmond Teo
06/09/2022, 3:24 PMadapter.submitList(topicsList.filterNotNull())
Vivek Modi
06/09/2022, 3:25 PMErick Sumargo
06/09/2022, 3:31 PMviewModel.topics
.filter { ... }
.flowOn(Dispatcher.Default)
.collect { ... }
Vivek Modi
06/09/2022, 3:37 PMDALDEI
06/19/2022, 8:11 AM