I have several maps with different combinations of keys for each map. I want to process each map but do different work depending on the set of keys available, basically dispatch on key availability. I thought clojure.spec might be a good fit for doing the classification step. So for each key, I could define a spec. Next, I would use clojure.spec.alpha/keys to define a spec for each set of keys I'd like to match. Finally, I would dispatch like so:
(fn [m]
(condp clojure.spec.alpha/valid? m
::foo-map-spec :do-foo-stuff
::bar-map-spec :do-bar-stuff))
Does this seem reasonable?
The advantage in my mind is its thorough, explicit, and easy to read. Possible downsides is performance if it mattered.
What are the advantages/disadvantages to this approach compared to other methods?