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

redrield

10/07/2018, 4:44 PM
if I have a Sequence from buildSequence, is there a way to collect all the elements it's already yielded and not care about anything else
d

Dominaezzz

10/07/2018, 4:50 PM
Why not just... stop iterating through the sequence.
r

redrield

10/07/2018, 4:56 PM
It's going to be an infinite sequence. in most cases i'm just going to care about the most recent elements its yielded but i do need a history which is why im not going with a channel
d

Dominaezzz

10/07/2018, 4:58 PM
Yeah, break out of the iteration or use
take
.
Hard to advise without example code.
Also,
Sequence
doesn't store history. It's basically a blocking
Channel
.
a

Allan Wang

10/07/2018, 7:12 PM
If you require history, maybe you could make something that subscribes to the sequence and appends it to a list. Then you can get the entire list whenever you want
d

Dico

10/07/2018, 9:53 PM
Yeah, you can use an iterator delegate.