This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-12
Channels
- # beginners (81)
- # boot (29)
- # cider (7)
- # cljs-dev (147)
- # cljsrn (5)
- # clojure (121)
- # clojure-austin (4)
- # clojure-conj (4)
- # clojure-italy (9)
- # clojure-russia (20)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (34)
- # clojurescript (137)
- # cryogen (2)
- # cursive (1)
- # data-science (1)
- # datomic (29)
- # events (9)
- # figwheel (1)
- # hoplon (14)
- # jobs (2)
- # luminus (2)
- # off-topic (7)
- # om (36)
- # onyx (6)
- # parinfer (14)
- # re-frame (13)
- # reagent (74)
- # specter (2)
- # test-check (1)
- # untangled (43)
- # vim (14)
- # yada (36)
hi All say I have a ns in which I want to define 2 specs , each for map for example:
(s/def ::a (s/keys :req-un [::value]))
(s/def ::b (s/keys :req-un [::value]))
the problem is that both maps require to have key :value
but there should be different specs of ::value
for each ::a
and ::b
how do I do it?(s/def :foo/value integer?)
(s/def :bar/value string?)
(s/def ::a (s/keys :req-un [:foo/value]))
(s/def ::b (s/keys :req-un [:bar/value]))
@lambder a
and b
in :a/value are not related to ::a in any implicit way, in case you might wonder
@alexmiller should we expect a big reveal for your talk in euroclojure, given the recent mentions of "dependency" related work happening? 🙂
no one expects the spanish inquisition
there are a few projects I have worked on over the last year in this area and the abstract is sufficiently vague to cover whatever I can talk about by the time I do the talk
@alexmiller
multispec assocs dispatch value back to the {} during s/exercise
, right?
is there a way to re-use same enrich {} with a dispatch value, but during s/conform
?
oh, I can just call multimethod on an actual {} to get the dispatch value ... assuming defmethod's return keyword, not an inline spec-from
I have a query (all-enums-of :my/attr)
that return's all my enums. There some how to dynamic gen (s/def :my/attr #{})
?
not sure I understand what the last sentence means - looks like you are trying to spec the empty set, which doesn’t make much sense?
I want to dynamic gen the spec of :my/attr
. In case, it's a enum so I describe it as a set of keys.... Maybe (s/def :my/attr (all-enums-of db :my/attr))
Should express better what I mean...
self reply
- Yep. I can do a macro, It's a good way? It will be declared after connect with the db. It's a problem?``
yes and yes
(defn load-enum-specs [db]
(let [enums (all-enums-of db :my/attr)]
(eval `(s/def :my/attr ~enums))))
Would be nice to have:
(defn load-enum-specs [db]
(let [enums (all-enums-of db :my/attr)]
(s/register :my/attr enums)))
well you’re just a macro away from that :)
(defmacro register [name spec]
(let [s (eval spec)]
`(s/def ~name ~s)))
this of course has the significant downside that it only works in a few cases like literal sets
or maybe wider than just those but not for things like preds, anonymous functions, etc