in reply to complex iterator needed

Dominus is in the process of writing a book on this. :-)

The idea is simple. For every control structure that you would like to use (eg loops), write a function allowing you to produce a parallel iterator control structure that is restartable. After you do that, you can write your function this style, and it is automatically an iterator.

For an illustration of the idea you can see me doing something similar (albeit on a non-ambitious scale) at Laziness in a more consistent way.