How to define a typedef with List<Vector>?


(Didier) #1

Do you know the solution to realize something like the following example :

 import haxe.ds.Vector
 typedef Toto = List<Vector>

to be able to do then a function like

function mafonction( unparam:Toto) { …

(Philippe) #2

Vector<T> needs a type, so you should write:

// Toto.hx
import haxe.ds.Vector;
typedef Toto<T> = List<Vector<T>>;

// usage
var t:Toto<Foo>;

If you want a generic “untyped” Toto you can defined the type as:

// Toto.hx
import haxe.ds.Vector;
typedef Toto = TotoOf<Dynamic>
typedef TotoOf<T> = List<Vector<T>>;

// usage
var t2:TotoOf<Foo>;
var t:Toto = t2;

Normally Toto as TotoOf<Dynamic> should unify with any TotoOf<T>.

(Rudy Ges) #3

By using Toto<T> like @elsassph said, you can also add a type parameter to your function like this:

static function myFunction<T>(param:Toto<T>)

See the manual on type parameters:

(Didier) #4

@kLabz and @elsassph thank you for the speed and quality of your answers ! :slight_smile:

(Philippe) #5

De rien mec.

(Rudy Ges) #6

De même :slight_smile: #100%FrenchThread