HaxeIterator.hx 587 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package python;
  2. import python.lib.Exceptions.StopIteration;
  3. import python.NativeIterator;
  4. class HaxeIterator<T>
  5. {
  6. var it :NativeIteratorRaw<T>;
  7. var x:Null<T> = null;
  8. var has = false;
  9. var checked = false;
  10. public function new (it:NativeIteratorRaw<T>) {
  11. this.it = it;
  12. }
  13. public inline function next ():T {
  14. checked = false;
  15. return x;
  16. }
  17. public function hasNext ():Bool {
  18. if (checked) {
  19. return has;
  20. } else {
  21. try {
  22. x = it.__next__();
  23. has = true;
  24. } catch (s:StopIteration) {
  25. has = false;
  26. x = null;
  27. }
  28. checked = true;
  29. return has;
  30. }
  31. }
  32. }