This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-23
Channels
- # announcements (2)
- # beginners (165)
- # boot (11)
- # cider (11)
- # clj-kondo (7)
- # cljdoc (1)
- # cljsrn (5)
- # clojure (120)
- # clojure-dev (21)
- # clojure-europe (3)
- # clojure-france (1)
- # clojure-italy (62)
- # clojure-nl (8)
- # clojure-spec (26)
- # clojure-uk (40)
- # clojuredesign-podcast (1)
- # clojurescript (3)
- # cursive (2)
- # data-science (2)
- # datomic (10)
- # emacs (2)
- # figwheel-main (1)
- # fulcro (17)
- # graphql (5)
- # hoplon (5)
- # jackdaw (15)
- # jobs (2)
- # juxt (1)
- # luminus (5)
- # off-topic (1)
- # onyx (11)
- # pathom (4)
- # pedestal (1)
- # re-frame (4)
- # reagent (11)
- # reitit (1)
- # remote-jobs (5)
- # shadow-cljs (48)
- # spacemacs (2)
- # specter (4)
- # sql (24)
- # tools-deps (25)
- # vim (82)
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?
make a spec with a custom gen
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?
yes, but you can just use the spec
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
the recommended way to do this with spec 1 is to make a spec with a custom generator
future answer may be different
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
spec 2 has some capabilities to create your own derived spec types with custom gens which is maybe another option
https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha#simple-spec-ops
but that's really trying to handle the case of parameterized things more so than pred generators
the example at that link doesn't show how to define a custom gen in a defop, but it has that capability
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.
not there now, but we have been thinking about how to add it
definitely a common case
it's a little tricky right now
you can spec it as an s/map-of s/tuple for map entries
possible to s/multi-spec the tuple on the key to choose the val spec