My application models Piano keys and I'm trying to write specs for them. My initial attempt was simple, they are a map of an octave and a key.
(spec/def ::octave (spec/int-in 0 9))
(spec/def ::key (spec/int-in 0 12))
(spec/def ::note (spec/keys :req-un [::octave ::key]))
The problem now is, that if the octave is zero, only A, A sharp, and B are valid keys. If the octave is 8 only C is a valid key.
This actually matters since converting piano keys to their number on the keyboard would otherwise result in invalid values, like -8 or 96.
My question is, is there a simple way to specify that depending on one value in a map, only certain values are valid for another key? This seems like a common enough problem. Or am I doing something fundamentally wrong?