Iterables

Have trying out iterables (iter(self)) and for most part they already work. The only thing is that they are supposed to throw a "StopIteration" exception when done. Seems that exception is not yet exposed in the Mojo SDK. Also when raising an exception, Mojo forces you to catch them at the caller side, which is not what you want when iterating. I guess just have to be patient until it is fully supported. But would love to be proven wrong if someone knows a hack?
2 Replies
Alex Kirchhoff
Alex Kirchhoff14mo ago
This is currently inconsistent with Python. Rather than relying on StopIteration, Mojo relies on the iterator's __len__ returning a non-negative value to know whether to continue iteration or not. This may be changed to be more consistent with Python in the future.
roboquant
roboquantOP14mo ago
Ahh, works like a charm. So len is not a static value but returns the remaining of the iterator (which actually makes sense for an iterator type). Thanks!!!
Want results from more Discord servers?
Add your server