Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 489
Matthew Molloy Avatar asked Mar 15 '23 17:03

Matthew Molloy


1 Answers

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.

like image 170
Gama11 Avatar answered Mar 26 '23 12:03

Gama11