Fork me on GitHub
#clojure-spec
<
2017-06-03
>
misha07:06:42

@xiongtx if you s/exercise it will complain about "no spec for key".

misha07:06:33

It is design decision, so you could opt in to writing detailed spec, instead of being forced to.

Alex Miller (Clojure team)20:06:08

@tclamb seems like a bug, but would be curious to see the actual value causing the error

tclamb20:06:10

@alexmiller s/exercise is generating maps with clojure.lang.LazySeq keys, like {(lazy-seq '(:r)) :r}

tclamb20:06:07

that passes s/valid? and s/conform

tclamb20:06:54

I didn’t expect this to be true as well: (identical? (s/conform spec x) x)

tclamb20:06:49

but I think that’s an artifact of the map value spec being keyword? instead of e.g. s/cat

tclamb21:06:09

I ran into this speccing a map-of point to tile for the board in a game like scrabble

stbgz21:06:31

hey all I am trying to wirite a spec that would satisfy some json data in which the keys have a shape but are not defined eg

{
        "x-identity": "2"
        "x-name": " aaa"
        "x-[some other string]": "bbb",
}

stbgz21:06:59

Can I use something like

(s/def ::x-object (s/keys ???)
where I can plugin a spec that describes the shape of the keys namely
%(string/starts-with? % "x-")

stbgz21:06:28

I though about using s/cat but that implies order of the keys

tclamb22:06:14

how about (s/map-of (s/and string? #(re-matches #"x-.+" %)) string?)?

stbgz22:06:18

@tclamb yeah just figured that out

stbgz22:06:34

now what if I have a json with a mix of well know keys and patterned keys like the ones above eg

{ 
         "name": .. , 
        "age":...,
        "x-internal"....
        "x-created"... 
}

stbgz22:06:18

I am modeling the well-know part of the spec with s/keys and the other with s/map-of however s/merge doesn’t seem to be working given that the “optional x...” could be 0, does merge understand optional?

tclamb22:06:26

the docs sound like s/merge only works with s/keys, not s/map-of

stbgz22:06:57

hmm this is harder than I though

stbgz22:06:21

I think I have to drop-down to everkv