I have a MutableStateFlow and a Flow variable. How can I set the initial value of selectedCollection as the first item of the collections Flow list?
ViewModel
@HiltViewModel
class HomeViewModel @Inject constructor(
private val collectionRepo: CollectionRepositoryInterface
) : ViewModel(){
var collections = collectionRepo.getCollections().asLiveData()
val selectedCollection = MutableStateFlow(//** Initial Value **//)
}
Repository Interface
interface CollectionRepositoryInterface {
fun getCollections() : Flow<List<Collection>>
}
Fragment
viewModel.collections.observe(viewLifecycleOwner){
collectionAdapter.submitList(it)
}