Fork me on GitHub
#clojure-spec
<
2018-03-23
>
pablore01:03:56

Are there any differences in using spec in clojure and clojurescript? Theres a cljs.spec.alpha namespace

pablore01:03:48

Can I define specs in a .cljc file and use them in both clojure and clojurescript?

seancorfield01:03:08

I believe that ClojureScript is supposed to do an automatic mapping from clojure.* namespaces to cljs.* namespaces so I would expect you could just write .cljc files with a require of clojure.spec.alpha and it should just work...

seancorfield01:03:27

(caveat: I don't do anything with cljs so I might be talking nonsense)

benzap01:03:16

I believe that is correct, I just pull in clojure.spec.alpha, and it works in clj, cljs, and cljc

borkdude16:03:03

Is there a way to not have this conform in the two options but just pass through as it is?

(s/def :dropdown.option/id (s/or :s string?
                                 :k keyword?))

borkdude16:03:12

so without the :s or :k

taylor16:03:39

could you s/and it with a conformer that discards the tag?

borkdude16:03:10

I am using s/and already I run into this in the conformer 😛

borkdude16:03:34

but I can just say (fn [id] (or (keyword? id) (string? id))) of course

taylor16:03:13

(s/def ::s-or-n
  (s/and (s/or :s string? :n number?)
         (s/conformer second)))
(s/conform ::s-or-n "hey")
=> "hey"
was what I was suggesting but not sure if that’s a terrible idea or not

Alex Miller (Clojure team)16:03:51

You can wrap s/nonconforming around the or

💡 4
Alex Miller (Clojure team)16:03:13

Currently that’s undocumented

Alex Miller (Clojure team)16:03:31

I think we will ultimately either doc it or make a nonconforming or

borkdude16:03:36

hmm, not in clojurescript yet probably?

borkdude16:03:06

works great, thanks