You could use a task, but the performance would be much less good than 
explicitly manipulating the iteration state for many things.


> On Jun 2, 2015, at 6:45 PM, Yichao Yu <[email protected]> wrote:
> 
> I'm wondering what is the best way to do the equivalant with the
> following in python.
> 
> ```
> In [1]: a = range(20)
> 
> In [2]: it = iter(a)
> 
> In [3]: for i in it:
>   if i == 10:
>       break
>  ...:
> 
> In [4]: for i in it:
>  ...:     print(i)
>  ...:
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> ```
> 
> I know that I can call `start`, `next` and `done` manually but it
> would be nice if I can avoid that.
> 
> I could also wrap the returned value of next in a type but I don't
> know how to make it both generic and fast, e.g. I want the typeinf to
> infer the type as easy as if I call the `start`.... methods manually
> and I don't want to rely on `next` being type stable (and AFAICT, the
> `next` for Any array is not).
> 
> 
> The exact format doesn't have to be the same with the python version
> but I do want to use `for` loop instead of `while`.

Reply via email to