Here's the basic goal:
We have a set of Events. We have a set of EventHandlers that use specific subsets of the Events. Some handlers handle one of the events or a few specific ones or all. By "handle", I mean the handler will return a Command in response to the event. It will always return a Command. Seemed natural to write the Events as an enum
enum Event {
Event1,
Event2,
Event3,
}
We need to collect all the arbitrary number of event handlers into a list. The number and type of event handlers varies on each list and who's using that list. So not every list is the same.
Now here's the problem. When we get an event, we need to iterate over our list of event handlers and pass them the event. Not all event handlers can handle each and every single type of event, so it follows we must return from the event handlers a Option in case they are passed an event they don't handle.
The alternative is to expression match on events before passing them to handlers and only pass the event to a handler it can handle. I don't like this way. But I kinda don't like the Option way either. Seems wrong to pass an event to a handler that doesn't care about it. Yet, we have a list of arbitrary handlers. Is there some way to give to a set of handlers an event but only the handlers that care about that event, maybe through some combination of conditional enum variants/generics/const generics/patterns? I almost believe the advanced type system can help me here.