package python; import python.lib.Types; class HaxeIterator { var it :NativeIterator; var x:Null = null; var has = false; var checked = false; public function new (it:NativeIterator) { 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; } } }