HaxeIterator.hx 531 B

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