Here is a small example of combining spec-based dispatch via multi-methods with hierarchies. https://gist.github.com/Azel4231/53b610befc62085a87666bb812ec118e
It’s super interesting how you can mix and match Clojure’s mechanisms.
Is this useful?
Parsing by content: yes
I can imagine specs to be useful for business rules. e.g. „if the person info misses an email address, we need to ask for it during the next call“. The person table might have a renderer that says: „if the spec ::missing-email applies display the person’s name in bold“. It’s also a good example of a „closed“ spec, that is only extended internally.
Hierarchy per multimethod: yes
How often have you encountered a class hierarchy in Java that forced you into overriding a method, or copying code or prevented reuse? That’s why multimethods can be given their own hierarchy. So you can build the hierarchy you need and it can be different for every method.
Parsing by content, or detecting the semantics of a thing via its value is really useful. As are hierarchies for multimethods.
This still does not cover the even more interesting case of a map that has multiple types at the same time. Or a map that applies to multiple specs at the same time. Which is a topic I have been wanting to write about for years. Oh well…