Mappare e combinare i Flow
Trasformi i flussi prima che raggiungano lo schermo.
Mappare e combinare i Flow è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Jetpack Compose Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Jetpack Compose Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Shape Data Before the UI
Raw data rarely matches what the screen needs. You use flow operators to transform a stream into ready-to-render UI state.
Transform with map
The map operator runs a function on each emission and passes the result downstream, leaving the original stream untouched.
val names = users.map { it.name }Filter Out Noise
Use filter to drop emissions you do not care about, so only the items that pass your condition reach the UI.
val active = users.filter { it.isActive }Combine Two Streams
The combine operator merges multiple flows and re-runs whenever any of them emits, giving you the latest value from each.
combine(query, results) { q, r -> SearchUi(q, r) }Combine Builds UI State
A common pattern is to combine several source flows into one immutable UiState object that fully describes the screen.
combine(items, loading, error) { i, l, e ->
UiState(i, l, e)
}Wait for All with zip
While combine fires on any change, zip pairs emissions one-to-one and waits until both flows have produced a new value.
flowA.zip(flowB) { a, b -> a + b }Switch to a New Stream
With flatMapLatest a new value cancels the previous inner flow and switches to a fresh one, perfect for live search.
query.flatMapLatest { repo.search(it) }Operators Are Cold by Default
Transformations like map and filter are cold: they describe work but do nothing until something downstream collects.
Chain Operators Freely
You can chain operators into a pipeline. Each one reads the stream above it and feeds the one below, top to bottom.
users.filter { it.isActive }
.map { it.name }Handle Errors in the Chain
The catch operator intercepts exceptions upstream so you can emit a fallback instead of crashing the whole stream.
repo.load().catch { emit(emptyList()) }Keep Logic in the ViewModel
Do your combine and map work in the ViewModel, then expose one clean state flow. The Composable stays simple and dumb.
Quick Check
Pick the operator for the job.
Recap: Mapping & Combining
Great work! Operators like map, filter, and combine reshape and merge streams in the ViewModel so the UI gets exactly the state it needs. 🎯
Domande Frequenti
La lezione «Mappare e combinare i Flow» è gratuita?
Sì — il testo completo di «Mappare e combinare i Flow» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Jetpack Compose Academy, passa a CoddyKit PRO. Il corso Jetpack Compose Academy include 4 lezioni in totale.
Cosa imparerò in «Mappare e combinare i Flow»?
Trasformi i flussi prima che raggiungano lo schermo. Eserciti Jetpack Compose Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Jetpack Compose Academy?
Non è richiesta alcuna esperienza precedente. Jetpack Compose Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Mappare e combinare i Flow»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Jetpack Compose Academy?
Sì. Ogni lezione Jetpack Compose Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- StateFlow e SharedFlow a confronto
- Mappare e combinare i Flow
- stateIn e WhileSubscribed
- Eventi una tantum con i Channel