I'm trying to convert a while(x.hasNextPart()) loo...
# getting-started
b
I'm trying to convert a while(x.hasNextPart()) loop into a sequence; so far I've found generateSequence but I'd need to bundle up the hasNext boolean so I can stop, e.g.
generateSequence { Elem(it.hasNextPart())}.takeUntil {it.hasNext}
is there a better way to do that? and in that case, would you prefer an Iterator instead?
✅ 1
K 1
j
You can keep the
while
loop inside a
sequence
builder instead. Then all consumers can use the sequence
b
and just yield inside the loop?
👌 1
thanks 🙂