Are you asking about the task approach or the manual iteration approach? Manual iteration, yes (otherwise all iteration would be slow); tasks, I'm not sure how inlining would be possible.
On Thu, Jun 4, 2015 at 8:52 AM, Yichao Yu <[email protected]> wrote: > On Wed, Jun 3, 2015 at 3:16 PM, Stefan Karpinski > <[email protected]> wrote: > > You could use a task, but the performance would be much less good than > explicitly manipulating the iteration state for many things. > > > > Manually iterating is not that bad so I think I would prefer a > solution that yield similar performance. > > Actually, can(/is it reasonable to make) type inference inline the > type as well if all use of it are inlined? > > > > >> 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`. >
