This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-28
Channels
- # arachne (2)
- # aws (5)
- # aws-lambda (5)
- # beginners (4)
- # boot (25)
- # cljs-dev (270)
- # cljsjs (1)
- # cljsrn (72)
- # clojars (5)
- # clojure (201)
- # clojure-belgium (5)
- # clojure-brasil (4)
- # clojure-italy (2)
- # clojure-korea (2)
- # clojure-russia (24)
- # clojure-spec (24)
- # clojure-uk (22)
- # clojurebridge (1)
- # clojurescript (125)
- # cloverage (3)
- # cursive (41)
- # datomic (37)
- # dirac (4)
- # emacs (2)
- # hoplon (421)
- # lein-figwheel (1)
- # leiningen (5)
- # luminus (2)
- # mount (1)
- # off-topic (18)
- # om (44)
- # om-next (4)
- # onyx (44)
- # pedestal (3)
- # proton (9)
- # re-frame (21)
- # reagent (21)
- # ring-swagger (12)
- # specter (9)
- # sql (2)
- # untangled (62)
- # vim (16)
I can’t find a good solution to write different specs that all have a :db/id
key but with different values
@jfntn what do you mean by ‘different values’?
Well one would be say a ::temp-entity
spec that’d check that :db/id
is a datomic/tempid
, and the other would be an ::entity
spec that would check that :db/id
is an entity id (long)
So I need to attach multiple specs to the same namespaced key, but s/or
won’t do since the point is to be able to assert whether an entity is temporary or not...
I found a weird trick using multiple slashes in the spec name and using :req-un
in the spec, but those don’t seem to really be supported since I’m getting intermitent analyzer errors and the keys won’t compile in cljs
I think in this case, I would use s/or
, and use the conformed value to say whether it’s a temp id or not
if you’re spec-ing a function that needs to take a temp entity, or something like that, you could always make a predicate function, temp-entity?
or some such, that conforms its argument and checks which branch s/or
took
Not as direct, but I’m able to express what I wanted, which is a reusable keys
spec and combine it with the temp and final specs
Hi, while trying to migrate from schema to spec I've come across an issue. Following the guide I was able to define specs for maps, but I think I have a case that is not covered. Basically the same key i.e. :id or :name may be an attribute of different entities. If I define ::name then the only way to use a different type definition for :name is to use namespaces which puts me in sort of OO style when I keep module per "noun".... Is there not a way to decouple key from value so that I can define i.e. ::plan-name type, but use :name in my map?
basically, you'd have multiple namespaced specs for name
: :foo/name, :bar/name; and then use them in map specs, but inside :req-un (or :opt-un), with the only requirement of keeping (name kw)
identical
(s/def :foo/id int?)
(s/def :bar/id string?)
(s/def :foo/thing (s/keys :req-un [:foo/id]))
(s/def :bar/thing (s/keys :req-un [:bar/id]))
(s/valid? :foo/thing {:id 1})
=> true
(s/valid? :foo/thing {:id "one"})
=> false
(s/valid? :bar/thing {:id "one"})
=> true
(s/valid? :bar/thing {:id 1})
=> false
hell yes 🙂 That looks like what I was looking for. I makes sense to document more how namespacing looks in action. I am gonna try this one in a moment. thanks
it works. I guess for Datomic that :xxx/yy pattern is heavily used (I have not used it though). thanks again!
Is there anyone here who can shed any light on my customer generator for an atom holding a map? https://clojurians.slack.com/archives/clojure-spec/p1474549130002028
Another question. Given this definition (s/def ::email (s/and string? #(re-matches email-regex %))) I am not able to generate a sample getting "Couldn't satisfy such-that predicate after 100 tries".
@przemek https://github.com/gfredericks/test.chuck has a string-from-regex
generator