> Should I/can I ever count on an iterator in Nim to handle the structure being
> changed during iteration?
Not unless the implementation promises to handle it, I suppose. There's nothing
implicit in an iterator that stops it from being affected by changes in the
structure. e.g.
iterator foo[T](s: seq[T]): T =
var i = 0
while i < s.len:
yield s[i]
inc i
var s = @[1, 2, 3, 4, 5]
for t in foo(s):
echo t
s.add(123)
> Is there any way to leverage Nim's type system or metaprogramming
> capabilities to create an iterator that forbids modifying the structure?
Maybe you could use the effect system somehow. I'm by no means a Nim expert,
though, so I don't know it's possible.