# Variadic Type Parameters

**URL:** <https://community.haxe.org/t/variadic-type-parameters/2194>\
**Category:** Haxe\
**Created:** [December 29, 2019, 7:07pm UTC](https://community.haxe.org/t/variadic-type-parameters/2194 "2019-12-29T19:07:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![redefrec](https://community.haxe.org/user_avatar/community.haxe.org/redefrec/32/1174_2.png) [@redefrec](https://community.haxe.org/u/redefrec)\
**Post date:** [December 29, 2019, 7:07pm UTC](https://community.haxe.org/t/variadic-type-parameters/2194/1 "2019-12-29T19:07:55Z")

</div>

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.

```haxe
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).

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [December 29, 2019, 7:32pm UTC](https://community.haxe.org/t/variadic-type-parameters/2194/2 "2019-12-29T19:32:59Z")

</div>

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

> <https://gist.github.com/nadako/b086569b9fffb759a1b5>

---

<div class="post-metadata">

**Author:** ![Slander](https://community.haxe.org/user_avatar/community.haxe.org/slander/32/1096_2.png) [@Slander](https://community.haxe.org/u/Slander)\
**Post date:** [December 29, 2019, 10:24pm UTC](https://community.haxe.org/t/variadic-type-parameters/2194/3 "2019-12-29T22:24:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [December 29, 2019, 10:45pm UTC](https://community.haxe.org/t/variadic-type-parameters/2194/4 "2019-12-29T22:45:54Z")

</div>

Sure, [https://unlicense.org/](https://unlicense.org/). Please abide!
