Two operators — map and flatMapConcat — look similar but serve fundamentally different purposes. Choosing the wrong one either causes a compile error or, worse, silently wraps a Flow inside another Flow and breaks your chain. The distinction comes down to one question: what does your transform return?
map: Transform Returns a Plain Value
map takes each value from upstream, runs a transformation on it, and emits the result downstream. The transformation returns a plain value — not a Flow.
apiHelper.getUsers() // Flow<List<ApiUser>>
.map { apiUserList ->
convertToUserList(apiUserList) // returns List<User> — plain value
}
.collect { userList ->
showInUI(userList)
}
convertToUserList is an in-memory conversion. It loops over ApiUser objects and maps them to User objects. No network call. No database query. It completes in microseconds and returns a list — not a Flow.
The return type of the lambda inside map is R — whatever value you return directly. If you return a List<User>, the downstream receives a List<User>.
flatMapConcat: Transform Returns a Flow
flatMapConcat is used when the transformation itself is a heavy operation — a network call, a database query, anything that takes time and returns a Flow.
apiHelper.getUsers() // Flow<List<ApiUser>>
.flatMapConcat { apiUserList ->
apiHelper.getMoreDetails(apiUserList) // returns Flow<Details>
}
.collect { details ->
showInUI(details)
}
getMoreDetails is another network call. Network calls return Flow<Something> when wrapped in the Flow API. If you tried to use map here, your transform would return Flow<Details> and the outer chain would become Flow<Flow<Details>> — an extra layer you never wanted and cannot collect normally.
flatMapConcat unwraps that inner Flow and flattens it back into the single stream the collector expects.
The key difference:
map | flatMapConcat | |
|---|---|---|
| Transform returns | Plain value R | Flow<R> |
| Use when | Quick in-memory conversion | Another network/DB call |
| Nesting | None | Flattens inner Flow automatically |
flatMapConcat Runs in Series
The “Concat” in the name describes order: tasks run one after another. The inner Flow for the first item must complete fully before the inner Flow for the second item starts.
Item 1 → inner Flow starts → inner Flow completes → result emitted downstream
Item 2 → inner Flow starts → inner Flow completes → result emitted downstream
Item 3 → ...
This is the correct behaviour when tasks depend on each other. If the second call needs the result of the first, series execution is required.
The Decision Rule
Ask one question about your transform:
Does the transform perform a network call, database query, or any operation that returns a Flow?
- Yes → use
flatMapConcat - No → use
map
Real-World Example: Upload Image Then Update Profile
A common sequential workflow:
- Upload a profile picture — returns the uploaded image URL.
- Call updateProfile with the username and that URL — depends on step 1 completing first.
uploadProfileImage(imageFile) // Flow<String> — emits the URL
.flatMapConcat { imageUrl ->
updateProfile(username, imageUrl) // Flow<Response> — uses the URL
}
.flowOn(Dispatchers.IO)
.collect { response ->
showSuccess(response)
}
You cannot run these in parallel — updateProfile needs the URL from uploadProfileImage. flatMapConcat enforces the series order: upload completes → URL arrives → updateProfile starts.
If you used map here, the transform would return a Flow<Response> and the chain would silently become Flow<Flow<Response>> — a compile warning at best and a runtime puzzle at worst.
A More Complex Scenario
Suppose the task is: run two network calls in parallel, then after both complete, save the combined result to a database.
// Step 1: zip for parallel calls (covered in the next post)
val combinedFlow = flowOne.zip(flowTwo) { result1, result2 ->
result1 + result2 // combine results — plain value
}
// Step 2: save to DB — DB call returns Flow
combinedFlow
.flatMapConcat { combinedData ->
database.save(combinedData) // Flow<Unit>
}
.collect { /* done */ }
The zip produces a plain combined value — use map or the zip transform directly. The DB save is a Flow-returning operation — use flatMapConcat.
Summary
Plain value transform? → map { ... }
Flow-returning transform? → flatMapConcat { ... }
flatMapConcat: series execution, maintains order
The next post covers zip for parallel network calls and how to handle errors per-task so one failure does not cancel the other.