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 { if (!checked) hasNext(); checked = false; return x; } public function hasNext ():Bool { if (!checked) { try { x = it.__next__(); has = true; } catch (s:StopIteration) { has = false; x = null; } checked = true; } return has; } }