Matthew Molloy
Matthew Molloy

Reputation: 1186

Haxe Interface that extends Iterable

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?

Upvotes: 4

Views: 342

Answers (1)

Gama11
Gama11

Reputation: 34148

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.

Upvotes: 7

Related Questions