Fork me on GitHub
#clojure-spec
<
2019-05-01
>
vemv16:05:16

(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)

valerauko16:05:03

not that i know of, no

vemv16:05:35

Working around that with a fn for now 🙂

eskemojoe00720:05:02

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.

drone20:05:47

(s/map-of string? string?)

👍 4
eskemojoe00720:05:02

Well that was easy...

eskemojoe00720:05:33

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?

seancorfield20:05:03

@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.

eskemojoe00720:05:31

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