Fork me on GitHub
#clojure-spec
<
2019-07-23
>
henryw37412:07:26

I want to have generators associated with predicates, like you have already with the clojure.core preds. Are people re-binding gen.alpha/gen-builtins or is there some other way?

Alex Miller (Clojure team)13:07:35

make a spec with a custom gen

henryw37413:07:45

but with string?, I can use that both as a normal pred, and as a spec with a generator. If I make a spec with the pred, that's two separate things isn't it?

Alex Miller (Clojure team)13:07:49

yes, but you can just use the spec

henryw37413:07:42

ok, so I'm hearing the core pred fns are a bit special wrt specs. I'm creating a library and really it'd be nice for the preds to be used in the same way as the core fns. https://github.com/henryw374/time-specs/blob/master/src/time_specs/core.cljc

Alex Miller (Clojure team)13:07:49

the recommended way to do this with spec 1 is to make a spec with a custom generator

Alex Miller (Clojure team)13:07:01

future answer may be different

henryw37413:07:30

ok thanks for the info.

Alex Miller (Clojure team)13:07:02

rebinding gen-builtins from a lib is problematic - users have to do that for it to work, and whatever you do has to be compatible with whatever some other lib might do

henryw37413:07:49

yeah... I'll avoid that I think. bound to be problems

henryw37413:07:56

no pun intended

Alex Miller (Clojure team)13:07:37

spec 2 has some capabilities to create your own derived spec types with custom gens which is maybe another option

Alex Miller (Clojure team)13:07:07

but that's really trying to handle the case of parameterized things more so than pred generators

Alex Miller (Clojure team)13:07:19

the example at that link doesn't show how to define a custom gen in a defop, but it has that capability

henryw37413:07:50

ok cool. I'll have a look at that with an eye to the future. on the topic of spec2, with select, say I have a schema with a key a the spec of which is a coll-of x or map-of string? x and x is a schema with keys foo, bar. could you do a select so say you want a and in the value of a you want to select key foo from x? I guess not from what I've read so far, but I think that'd be useful.

Alex Miller (Clojure team)14:07:15

not there now, but we have been thinking about how to add it

Alex Miller (Clojure team)14:07:23

definitely a common case

henryw37414:07:56

cool thanks, looking forward to spec2 definitely

robertfw22:07:08

What is the recommended way to spec a map that uses strings for keys?

Alex Miller (Clojure team)22:07:13

it's a little tricky right now

Alex Miller (Clojure team)22:07:20

you can spec it as an s/map-of s/tuple for map entries

Alex Miller (Clojure team)22:07:39

possible to s/multi-spec the tuple on the key to choose the val spec

robertfw22:07:54

Will that become easier with spec2?