COMMUNITY

Variadic Type Parameters

If I want to create a generic class that can store and call functions of some specific (but generic) type, what would be the best way to achieve that in Haxe in a typesafe way?

e.g.

var onSpawn: Dispatcher<>;
var onKill: Dispatcher<Unit>;
var onDeath: Dispatcher<Unit>;
var onDealDamage: Dispatcher<Int, DamageType, Unit>;
...
onDealDamange.register(some_function_or_delegate, order);
onDealDamange.register(another_function_or_delegate, order);
...
onDealDamage.call(20, Physical, aUnit);

I would like to implement Dispatcher, such that I don’t have to introduce any new types manually whenever I have a new dispatcher (with new type parameters).

1 Like

Rest type parameters + @:genericBuild? :slight_smile: Nice code snippet by @nadako:

3 Likes

That’s pretty amazing. Does @nadako have a license for said code?

Sure, https://unlicense.org/. Please abide!

1 Like