NativeIterable.hx 866 B

12345678910111213141516171819202122232425262728
  1. package python;
  2. import python.HaxeIterable;
  3. import python.NativeIterator;
  4. /**
  5. This type represents native python iterables (objects that implement __iter__() method).
  6. It supports haxe iteration and conversion to `Iterable` by creating wrapper objects.
  7. **/
  8. abstract NativeIterable<T>(NativeIterableRaw<T>) to NativeIterableRaw<T> from NativeIterableRaw<T> {
  9. /**
  10. Return haxe `Iterable` object wrapping `this` native iterable.
  11. **/
  12. @:to public inline function toHaxeIterable():HaxeIterable<T> return new HaxeIterable(this);
  13. /**
  14. Return haxe `Iterator` object by wrapping `this.__iter__()` native iterator.
  15. **/
  16. public inline function iterator():HaxeIterator<T> return new HaxeIterator(this.__iter__());
  17. }
  18. /**
  19. Native python iterable protocol.
  20. **/
  21. typedef NativeIterableRaw<T> = {
  22. function __iter__():NativeIterator<T>;
  23. }