isn't there a way to continuously ask sequence for...
# advent-of-code
k
isn't there a way to continuously ask sequence for any number of items?
sequence.take(3) sequence.take(5) ... ?
🤷‍♂️ 1
e
sequence and iterable are stateless, they don't remember how much you've consumed. every new use is independent
on the other hand, iterator is stateful. every time you iterate a sequence or iterable (collection), you get a new iterator
❤️ 1
👀 1
so, if you want state to persist… hold onto the iterator
e.g.
Copy code
val iterator = sequence.asIterable().iterator()
List(3) { iterator.next() }
List(5) { iterator.next() }
k
thaanks