I've been thinking a lot about an alternative to multimethods that use patterns in the definition and partial matching in dispatch. I imagine two kinds of this to be useful:
A single dispatch on the most specific match
Dispatches for all matches (like an exhaustive match)
2 is easy. I think I'd simply run match with a doseq and the patterns of all functions.
1 seems difficult. There has to be a notion of specificity, similar to CSS selectors
I'm aware this could bring about performance drawbacks since both approaches require looking at all patterns for each dispatch. However, I think the concept could be worth the while.
A few use case examples:
UI components that dispatch different implementations based on the data to be rendered. Currently this usually ends up in a nightmare of conditionals conflating the view code of the components (of course that too can still be done if needed). However, some views are radically different for different data, for example auth for logged-in? vs logged-out users.
Listening to a tx-log. Say a user adds a comment to some entity. If that entity already has comments on it, other users might want to get notified but if the entity has notifications set to false they would not. This makes a case for a specific dispatch.
And so on!
I don't mean to bug you since this is only tangentially related to meander but I do have interest and time to work on this and want to gauge how well meander could be suited for a project like this.
I've been thinking a lot about an alternative to multimethods that use patterns in the definition and partial matching in dispatch. I imagine two kinds of this to be useful:
match
)2 is easy. I think I'd simply run
match
with adoseq
and the patterns of all functions. 1 seems difficult. There has to be a notion of specificity, similar to CSS selectorsI'm aware this could bring about performance drawbacks since both approaches require looking at all patterns for each dispatch. However, I think the concept could be worth the while.
A few use case examples:
UI components that dispatch different implementations based on the data to be rendered. Currently this usually ends up in a nightmare of conditionals conflating the view code of the components (of course that too can still be done if needed). However, some views are radically different for different data, for example
auth
for logged-in? vs logged-out users.Listening to a tx-log. Say a user adds a comment to some entity. If that entity already has comments on it, other users might want to get notified but if the entity has notifications set to false they would not. This makes a case for a specific dispatch.
And so on!
I don't mean to bug you since this is only tangentially related to meander but I do have interest and time to work on this and want to gauge how well meander could be suited for a project like this.