This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-31
Channels
- # announcements (3)
- # beginners (139)
- # boot (28)
- # cider (40)
- # cljdoc (1)
- # cljs-dev (30)
- # clojure (61)
- # clojure-conj (1)
- # clojure-dev (113)
- # clojure-germany (4)
- # clojure-italy (29)
- # clojure-nl (3)
- # clojure-russia (2)
- # clojure-spec (38)
- # clojure-uk (53)
- # clojurescript (188)
- # core-async (4)
- # css (2)
- # cursive (7)
- # data-science (5)
- # datomic (14)
- # emacs (1)
- # figwheel-main (192)
- # fulcro (37)
- # jobs-discuss (1)
- # mount (4)
- # off-topic (47)
- # pedestal (7)
- # portkey (14)
- # re-frame (4)
- # reagent (22)
- # reitit (2)
- # remote-jobs (1)
- # ring (6)
- # shadow-cljs (65)
- # spacemacs (7)
- # specter (6)
- # yada (8)
Help! I need my generated test data to have unique ids in various places (not uuids, though, just positive integers). I hacked a stateful generator (using an atom) for that which cannot be the right way…? How do I do stateful generators? exercise
and sample
seem to have no way to allow a state…
maybe i misunderstood. If you want to use specs defined in one namespace, just require that namespace where you wish to use the spec. If it is in a lib the declaring namespace should be in the lib’s jar … Is that what you asked?
@ulrich.becker you can do an ugly hack with gen/fmap with a closed around atom and a (gen/return nil)
something like that: (gen/sample (let [a (atom 0)] (gen/fmap (fn [_] (swap! a inc)) (gen/return nil))))
@misha we share specs between a backend clojure repo and a frontend clojurescript repo at my work by putting the specs in a third repo that has the specs in cljc files. It works pretty well IMO.
@ulrich.becker it's similar yeah
But the need for unique ids is very real, somebody must have a better solution? (except using UUIDS)
I guess another alternative is to let the random part untouched and keep track of values used in one way or another, I guess again you can do that with an atom or something. Still feels a bit odd
something like that? (let [bin (atom #{})] (gen/such-that (fn [x] (and (not (get @bin x)) (swap! bin conj x)) ) (gen/int)))
just for fun another dirty trick: (gen/fmap hash (gen/uuid)), but you would get neg values, so (gen/sample (gen/fmap #(bit-and (hash %) 0x7FFFFFFF) (gen/uuid)))
would work (with potential collisions tho)
@codonnell will sending specs as an edn make any sense?
I'm not sure what you mean by this. Could you elaborate?
front-end sends "back-end, give me your specs" back-end responds with subset of spec registry as edn front-end reads, evals
I suppose you could do this if you need to update specs at runtime. I haven't personally run into a scenario where building a static registry at compile time was insufficient.
general question about spec: one of the things that keeps coming up for me, is that I’d like a language to describe a schema or shape of data that I would need to translate to some other schema language (e.g. GraphQL, dynamoDB, etc.). As a spec neophyte, my first instinct/desire is to reach for clojure.spec as the schema language, and somehow convert the spec to the other schema language. But the more I think about it, the more it feels like spec is much better setup to be the tool to do the conversion, and it’s left up to me to create my own schema language in Clojure. Which one is correct?
I think there was some project that went from spec to various schema formats, but I can’t seem to recall it right now