https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Paul Woitaschek

01/27/2020, 7:00 AM
Which version would you prefer: a or b? (and why)?
a

altavir

01/27/2020, 7:03 AM
Why do you need Flow here at all? You do not perform asynchronous operations.
p

Paul Woitaschek

01/27/2020, 7:04 AM
The pagedRecipeIListForIds returns a flow
(you can see the type hints in the first version)
a

altavir

01/27/2020, 7:07 AM
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

Paul Woitaschek

01/27/2020, 7:08 AM
I don't need a Flow<UUID>, i need a List<UUID>
a

altavir

01/27/2020, 7:09 AM
Why?
p

Paul Woitaschek

01/27/2020, 7:09 AM
Because the pageRecipeListForIds requires one
a

altavir

01/27/2020, 7:11 AM
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

Paul Woitaschek

01/27/2020, 7:11 AM
Yes it's a principal difference here
It's the flow flatMap
Not the collection one
a

altavir

01/27/2020, 7:14 AM
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

Paul Woitaschek

01/27/2020, 7:14 AM
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

altavir

01/27/2020, 7:17 AM
Ah, I see. Then the problem is that you have to dive into suspended world. Maybe
flowOf(tags). map{recipesByTags...}
?
p

Paul Woitaschek

01/27/2020, 7:17 AM
Hah now that is a suggestion 🙂
a

altavir

01/27/2020, 7:18 AM
Because otherwise it is not clear, where do you get a context for collection creation from.
5 Views