What is the advantage of using `asSequence` before...
# getting-started
n
What is the advantage of using
asSequence
before `filter`s and `map`s?
k
Otherwise you're creating a temporary collection between every step.
n
@karelpeeters thanks!
u
I still find that new inspection a bit annoying and turned it off. 😛
n
There are good rules to decide when to use
asSequence
https://proandroiddev.com/sequences-a-pragmatic-approach-9d4296086a9d
💯 1
s
And it behaves more like streams, an event flows through the entire steps before the next event is processed. Ex if you have take (2) and if your original input list had 1000 items, you would get performance improvements as well.
It does lack one feature when compared to Java streams, ability to schedule on multiple CPUs
n
Yes. Compare this:
(0..6000000).toList().find { it < 100 }
(about 3 seconds) and this:
(0..6000000).asSequence().find { it < 100 }
(a moment, asSequence is not needed here though)
a
Wow this is one of the first discussions where sequences really clicked for me. Thanks Alexander! 😄
🙂 1