Fork me on GitHub

(spec/def :foo/bar int?)

(spec/def :baz/quux string?)

(spec/keys :req [...])
Is it possible to define a keys spec such that the :foo/bar key is required, but the :baz/quux spec is validated for that specific key? i.e. I want to override a spec without renaming the key (rationale: :foo/bar is a Datomic attribute. I cannot or don't want to rename it. And :foo/bar has a existing spec, useful/correct 99% of the times)


not that i know of, no


Working around that with a fn for now 🙂


I have a hash-map where the keys and values are used almost as a linked list {"a" "b", "b" "c", "c" "a"} where a,b,c could be other strings. This is used in a map where I have a spec, but I don't know how to write a spec that says, let the keys and values be any ol' string.


(s/map-of string? string?)

👍 4

Well that was easy...


One more question for now. I have a unique ID for many items. They are used throughout the speced map. When using generators, it doesn't understand the relationships between the IDs. Any way to enforce that?


@david.folkner You can either (s/and (s/map-of ...) uniqueness-predicate) or write your own generator. The former is "easy" if it's able to actually satisfy the criteria. The latter is harder but more likely to work.


Perfect. I'll take a look at making a generator, that will likely fit my application a bit better. I already have the functions to build up the data for my actual application, so a custom generator can leverage those.

Alex Miller (Clojure team)21:05:09

for the latter, see gen/fmap and/or gen/bind