Hi,
sometimes I have the need to access an iterator directly, because the first element in a collection needs a special handling. It would be fine if I could access an iterator directly like this pseudo code:
var it = collection.items
var first: ElementType
if it.pop(first):
for e in it: # iterate over the remaining elements of the collection
dosomething(e)
Iterators are not first class yet and so are very restricted (but fast). They will turn into proper coroutines in the future and I am also thinking about making the for loop support a protocol like hasNext/next.
For now, use this idiom:
result = "["
for i, x in pairs(s):
if i > 0: result.add(", ")
result.add($x)
result.add("]")