package python; import python.lib.Exceptions.StopIteration; import python.NativeIterator; class HaxeIterator { var it :NativeIteratorRaw; var x:Null = null; var has = false; var checked = false; public function new (it:NativeIteratorRaw) { this.it = it; } public inline function next ():T { checked = false; return x; } public function hasNext ():Bool { if (checked) { return has; } else { try { x = it.__next__(); has = true; } catch (s:StopIteration) { has = false; x = null; } checked = true; return has; } } }