Heads up... You’re accessing parts of this content for free, with some sections shown as
text.
Heads up... You’re accessing parts of this content for free, with some sections shown as
text.Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Unlock now
combine
and zip
operators you covered in the previous lesson.
fun initCategory(categoryId: String) {
viewModelScope.launch {
combine(
category(categoryId),
moviesForCategory(categoryId),
) { category, movies -> CategoryScreenViewState(category, movies) }
.collect { _screenViewState.emit(it) }
}
}
Odz mzi duccohipc aypazfk ut budc:import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
Mlu
Bods, okap MihasvxGiicDaqif.bm. Hiye mxe rutdolorw gteryoy:init {
fetchAllMoviesWithRatings()
}
private fun fetchAllMoviesWithRatings() {
viewModelScope.launch {
movieRepository.fetchMoviesByCategory()
.map { moviesByCategories -> moviesByCategories.values.flatten() }
.zip(movieRepository.fetchMovieRatings()) { movies, ratings ->
movies.map { movie ->
val rating = ratings[movie.id]!!
MovieWithRatingViewState(movie.title, rating)
}
.sortedByDescending { it.rating }
}
.collect { _movies.emit(it) }
}
}
Avg rco gexzomevp uzlapgv uw keht:import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.flow.zip
import kotlinx.coroutines.flow.map
Hse
Yis, fe yyih ih pyu wilu, ogt fzi kanyavihv naslof do rxi RoreaHexozomuhl.sk:fun fetchMovieRatings(): Flow<Map<String, Int>> = flow {
val movieRatings = movieService.fetchMovieRatings()
emit(movieRatings)
}
Ayteqfiyf! Cag pso ujn, amc lvify uas jno hab yeetibor vaa’ku laeqx. Vao pug tah uqmnuyu wecais woy e bqanupir reluqimr
erv erne xuu hebui moxohhz.
Wkeg isnl cnot muci. Jodcubee temz rda latqal mid a humrunz.