This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-15
Channels
- # beginners (34)
- # boot (45)
- # cider (16)
- # cljs-dev (20)
- # cljsjs (1)
- # cljsrn (8)
- # clojure (207)
- # clojure-berlin (3)
- # clojure-dev (18)
- # clojure-greece (1)
- # clojure-ireland (1)
- # clojure-italy (9)
- # clojure-russia (20)
- # clojure-spec (27)
- # clojure-uk (19)
- # clojurescript (110)
- # code-reviews (2)
- # cursive (7)
- # data-science (2)
- # datomic (7)
- # devcards (1)
- # emacs (4)
- # graphql (1)
- # hoplon (2)
- # immutant (15)
- # jobs (5)
- # jobs-rus (1)
- # juxt (1)
- # luminus (7)
- # lumo (26)
- # microservices (3)
- # off-topic (27)
- # om (13)
- # onyx (11)
- # pedestal (7)
- # proton (4)
- # re-frame (24)
- # remote-jobs (1)
- # spacemacs (2)
- # specter (2)
- # unrepl (31)
- # untangled (7)
- # vim (14)
I'm trying to take a reagent vector, conform it, make a modification and unform it back.
(s/def :reagent/vector
(s/cat :element any? :props (s/? map?) :children (s/* any?)))
This conforms fine:
(s/conform :reagent/vector [:div {:a 3} [:div "1207"] [:div "w13"]])
;; => {:element :div, :props {:a 3}, :children [[:div "1207"] [:div "w13"]]}
but unforms back to a lazyseq - is there a spec I can use that will make unform turn it back to a vector?I tried prefixing with s/and vector
but I think that was wrong
@danieleneal Wrapping it in (s/and ... (s/conformer identity vec))
should do the trick
Oh or maybe you have to put it before the s/cat
really
Interesting ...
yeah (s/and (s/conformer identity vec) ...
works, thanks @dergutemoritz
is that appropriate/idiomatic do you know?
I guess that's an innocent enough use of s/conformer
, yeah ๐
Maybe we should call this kind of use "vegan" as opposed to the "meat grinder" pattern
"No animals were harmed in this use of s/conformer
"
the need for regex ops in a vector is a known issue - itโs pretty challenging right now to get conforming, validation, unforming, generation, and describing to work properly together
s/with-gen
e.g.
(def keyword-conformer
(s/with-gen
(s/conformer
(fn [x]
(cond (keyword? x) x
(string? x) (keyword x)
:else :clojure.spec/invalid)))
#(s/gen keyword?)))
works for me
I have several other specs like:
(s/def ::example (s/and keyword-conformer #{:some :specific :values}))
I've been working around that with
(s/def ::example
(s/with-gen
(s/and keyword-conformer
#{:some :specific :values})
#(s/gen #{:some :specific :values})))
but that feels gross. Is there a better way?(s/def ::example #{:some :specific :values "some" "specific" " "values"}) would work :)
What do you actually need to spec?