If I have to filter a list, is it always better (performance-wise) to convert it to a flow first or did I misunderstand something?
s
streetsofboston
12/13/2019, 9:40 AM
No, unless you really need a Flow, don't convert it to a Flow. Just keep it as a list and call
filter
on it. For large lists and if you call many operators on the list, you may want to convert it to a
Sequence
.
streetsofboston
12/13/2019, 9:41 AM
Also, avoid optimizing (early) if you don't see or experience a performance issue. 😀
💯 3
a
Andreas Jost
12/13/2019, 9:46 AM
Thanks, but flows/sequences would make sense if I had a larger list of data entities and want to map it to a list of domain entities, and might also filter afterwards, right?
I will look up the difference between flow and sequence.
s
streetsofboston
12/13/2019, 10:03 AM
Flow is a (cold) stream of data. You'd need a Coroutine to collect the data emitted by a Flow. A Sequence is a 'lazy' view on a collection (list). No need for Coroutines.
âž• 1
a
Andreas Jost
12/13/2019, 10:05 AM
Understood, great explanation, thank you!
m
Matteo Mirk
12/24/2019, 9:36 AM
If it’s not a huge list, just call
list.filter {}
and be fine. I support what Anton said: don’t optimize prematurely, only if you experience a slow execution.