You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
should throw an error, because there's no way to cycle a stateful iterator other than recording all iterations, imagine x here being a file Stream or something
This is what Python does. Ideally, we should do just that for stateful iterators.
If that is not feasible, we should have it error for any stateful iterator (which also includes EachLine iterators, and any Generators built on Stateful or Eachline, and so on, recursively.). The problem is that there is currently no way of figuring out if an iterator is stateful.
I propose the following:
Have Iterators.cycle check the statefulness trait. If stateful, store all seen element in a Vector. There will be some false positives here, i.e. stateless iterators that have no opted into the Stateless trait. That's unfortunate, but I believe it's a necessity.
The proposal above is non-breaking and will fix the behaviour of Iterators.cycle. The downside is that it will cause needless caching of results for stateless iterators which have not opted in to the upcoming IsStateless trait. I believe that is the best we can do.
MWE:
The 7 last elements of the vector are un-initialized and therefore set to arbitrary values (which could include #undef elements!)
This happens because
Iterators.cycle
assumes its underlying iterator is stateless and can be resumed from the beginning by callingiterate
.The text was updated successfully, but these errors were encountered: