class Test {
static function main() {
trace("Haxe is great!");
trace(test(new MyView<{myDataA:Int}>()).myDataA);
trace(test(new MyView<{myDataB:String}>()).myDataB);
}
static function test<T>(?view:MyView<T>):T {
return cast {
myDataA: 10,
myDataB: "hello"
};
}
}
abstract MyView
public inline function new() {
this = null;
}
}
Note that the inlined null constructor in MyView renders to just passing in null:
// Generated by Haxe 4.3.3 (function ($global) { "use strict"; class Test {
static main() {
console.log("Test.hx:3:","Haxe is great!");
console.log("Test.hx:4:",Test.test(null).myDataA);
console.log("Test.hx:5:",Test.test(null).myDataB);
}
static test(view) {
return { myDataA : 10, myDataB : "hello"};
}
} class haxe_iterators_ArrayIterator {
constructor(array) {
this.current = 0;
this.array = array;
}
hasNext() {
return this.current < this.array.length;
}
next() {
return this.array[this.current++];
}
} { } Test.main(); })({});
There could be many other applications of this technique for multivariate arguments, perhaps could be applied to the partial enum issue.