https://kotlinlang.org logo
#feed
Title
# feed
d

Dave Leeds

09/17/2019, 5:18 AM
Hello, everyone! I'm excited to share a new article - if you've ever wondered about when to use sequences and when to use collections, this one's for you! https://typealias.com/guides/when-to-use-sequences/
K 7
💯 5
👏 7
👍 25
n

nfrankel

09/17/2019, 7:29 AM
great didactic post
c

curioustechizen

09/17/2019, 7:59 AM
Raise your hand if you follow the "share first, read later" strategy when it comes to this blog. Every post is better than the previous. My new goal in life is to be able to explain difficult technical concepts with as much clarity as Dave Leeds does.
2
c

Chris Miller

09/17/2019, 9:24 AM
Great article. What's the "fantastic coroutine-based generator that puts the flow control into the generator function" that the article refers to?
d

Dave Leeds

09/17/2019, 12:10 PM
Thanks for the kind words, @nfrankel and @curioustechizen!
👍 1
@Chris Miller I should probably add a little more information to that spot. Meanwhile, you can find the official Kotlin sample for it here: https://github.com/JetBrains/kotlin/blob/1b889c976a7f21fdf000ecd1506643ac0a33eca3/libraries/stdlib/samples/test/samples/collections/sequences.kt#L112-L125
👍 1
n

nfrankel

09/17/2019, 6:38 PM
Well deserved
v

voddan

09/18/2019, 8:45 AM
Very well researched and written!
c

Cody Engel

09/25/2019, 6:28 PM
@Dave Leeds really enjoyed this article, I do have one question about the
toList()
performance hit though. Would providing a
capacity
for
toList
offset that performance hit? This is a crude example but something like this is possible today:
listOf<String>().asSequence().map { it }.sorted().toCollection(ArrayList(20))
So adding
toList(defaultCapacity: Int)
could clean it up a bit more. Just thinking for cases where the list size isn’t changing it’d be worth it just tell it what size it should be
d

Dave Leeds

09/26/2019, 2:14 AM
Hey @Cody Engel - thanks for asking! Yes, supplying the initial capacity yourself does help to mitigate the performance hit that you would otherwise get from using just
Sequence.toList()
. Naturally, you'd still want to take it in context with all of the other factors in play, but if you do know the size, your approach would help tip the scales back toward sequences. 👍
c

Cody Engel

09/26/2019, 1:37 PM
Gotcha, we have some situations where we are mostly just transforming objects so I think in those cases it would help. As soon as you apply a filter or something then all bets are off. Thanks, and again really great article 🙂
2 Views