Haxe Interface that extends Iterable

353 views Asked by At

I have an interface that extends Iterable (as well as other interfaces).

interface MyInterface extends Iterable {
  public function iterator ():Iterator<Dynamic>;
}

this gives me

MyInterface.hx:1: lines 1-3 : Invalid number of type parameters for Iterable

what is the correct way to proceed?

1

There are 1 answers

0
Gama11 On BEST ANSWER

Iterable is defined as a typedef, not an interface, so this can't work.

Simply adding a function named iterator() to your class will do the trick, no need to implement or extend anything. This mechanism is called structural subtyping.

There's more information about Iterators here.