Is there a way to create suspended iterators in Ko...
# getting-started
j
Is there a way to create suspended iterators in Kotlin? Much like the for .. await in javascript?
y
Yes. In fact, Flow already does that. It's as simple as defining an
operator fun MySuspendIterable.iterator(): MySuspendIterator
and
suspend operator fun MySuspendIterator.hasNext(): Boolean
,
suspend operator fun MySuspendIterator.next()
j
Very sweet! Thank you!
Is there any documentation on this anywhere? If not, could be useful 🙂
y
It's mentioned here, but not in great detail
❤️ 1
s
Iterator support is mentioned, but I'm surprised that this includes suspendable Iterators 🤷‍♂️