Which version would you prefer: a or b? (and why)?
# coroutines
p
Which version would you prefer: a or b? (and why)?
a
Why do you need Flow here at all? You do not perform asynchronous operations.
p
The pagedRecipeIListForIds returns a flow
(you can see the type hints in the first version)
a
Then you should create a collection, convert it to flow (https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/kotlin.collections.-iterable/index.html) and then use mapping operations. I am not sure, why you use
suspende {}
construct
p
I don't need a Flow<UUID>, i need a List<UUID>
a
Why?
p
Because the pageRecipeListForIds requires one
a
You still convert your list to flow and then use flatmap. You can either use flatmap on a collection and then concat flows, or you can convert a collection to a flow and then work with flows. No principial difference here.
p
Yes it's a principal difference here
It's the flow flatMap
Not the collection one
a
I know. It is OK, my correction is only about the generation of initial collection. You can use collection flatmap, get a list of flows and then merge them. The choice of proper method depends on how does your asynchronous operation works. In general I would prefer to goe with Flow flatMap the way you've done it.
p
The initial collection is suspending thats the thing here
(should have posted the initial screenshot with the suspending arrow hints in the first place)
a
Ah, I see. Then the problem is that you have to dive into suspended world. Maybe
flowOf(tags). map{recipesByTags...}
?
p
Hah now that is a suggestion 🙂
a
Because otherwise it is not clear, where do you get a context for collection creation from.