0Pricing
Jetpack Compose Academy · Lesson

Mapping & Combining Flows

Transform streams before they hit the screen.

Mapping & Combining Flows is a free Jetpack Compose Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. 🎯

Frequently asked questions

Is the “Mapping & Combining Flows” lesson free?

Yes — the full text of “Mapping & Combining Flows” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “Mapping & Combining Flows”?

Transform streams before they hit the screen. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Mapping & Combining Flows” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. StateFlow vs SharedFlow
  2. Mapping & Combining Flows
  3. stateIn & WhileSubscribed
  4. One-Off Events with Channels
← Back to Jetpack Compose Academy