This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-30
Channels
- # aleph (12)
- # beginners (23)
- # boot (12)
- # cider (40)
- # cljs-dev (8)
- # cljsrn (20)
- # clojars (1)
- # clojure (122)
- # clojure-canada (2)
- # clojure-dev (21)
- # clojure-gamedev (2)
- # clojure-italy (3)
- # clojure-nl (12)
- # clojure-norway (1)
- # clojure-sanfrancisco (3)
- # clojure-spec (59)
- # clojure-uk (114)
- # clojurescript (50)
- # clojurex (1)
- # cursive (2)
- # datascript (2)
- # datomic (26)
- # emacs (5)
- # fulcro (19)
- # garden (1)
- # hoplon (54)
- # leiningen (42)
- # luminus (14)
- # off-topic (24)
- # om (5)
- # onyx (7)
- # re-frame (2)
- # reagent (31)
- # reitit (3)
- # ring-swagger (39)
- # shadow-cljs (8)
- # sql (3)
- # tools-deps (13)
@clojurians.net thanks for you help. I have tried it and it returns empty []
. If I have the fdef in the same ns, and I run (st/instrument)
it works
Just tested it to make sure I'm not missing something, but it works for me. Have you made sure that the external namespace the fdef is in is :required?
yes it does. I feel like there is something missing as well, but I haven’t figured it out yet, it should work like your said.
if it gives that error saying it cant be satisfied after 100 tries or something, it won’t be able to be instrumented
@clojurians.net it’s defined in another namespace.
(s/fdef some-ns/button
:args (s/cat :opts (s/keys :opt-un [:button/type :button/state :button/size
::class])))
This is a question about clojure.spec.alpha as an example code base, rather than about using it. In the following code, it seems to me as though alpha.clj is working very hard to avoid multimethods. Does anyone have insight into why?
(defprotocol Specize
(specize* [_] [_ form]))
(extend-protocol Specize
clojure.lang.Keyword
(specize* ([k] (specize* (reg-resolve! k)))
([k _] (specize* (reg-resolve! k))))
clojure.lang.Symbol
(specize* ([s] (specize* (reg-resolve! s)))
([s _] (specize* (reg-resolve! s))))
Object
(specize* ([o] (spec-impl ::unknown o nil nil))
([o form] (spec-impl form o nil nil))))
(defn- specize
([s] (c/or (spec? s) (specize* s)))
([s form] (c/or (spec? s) (specize* s form))))
protocols are faster
in this particular case, the protocol has one method, so that’s not a concern
Hmm, I’m thinking of it quite differently. The Specize protocol is allowing keywords, symbols, and (to a degree) objects to participate in the multiple-method Spec protocol, instead of using multi-methods. For example:
(defn conform
"Given a spec and a value, returns :clojure.spec.alpha/invalid
if value does not match spec, else the (possibly destructured) value."
[spec x]
(conform* (specize spec) x))
(defn unform
"Given a spec and a value created by or compliant with a call to
'conform' with the same spec, returns a value with all conform
destructuring undone."
[spec x]
(unform* (specize spec) x))
is there a good spec function that will return the req-un’ed keys for a spec defined map?
example. i have a record blah
{:a a :c c :e e }
and a spec def (s/def ::blah-fact
(s/keys ::req-un [::a ::e])
whats the best way to call a function to get back #{:a :e}
?@ben.borders Here's one way:
user=> (s/def ::mymap (s/keys :req-un [::boo ::bar]))
:user/mymap
user=> (-> (apply hash-map (-> ::mymap s/form rest)) :req-un)
[:user/boo :user/bar]
Hi, I’m working on a system of clojure based services, that passes messages based on clojure maps around. So Im thinking I can just create a common module of specs (or at least a common as they need to be), but I have one other potential wrinkle. We basically need to support ‘tenants’. So I might have the same attribute, that means the same thing throughout the system (s/def :account/number ; like "A123")
so far so good. But for another tenant maybe :account/numbers should start with “B”.. Is a good way to handle this ?
note that that won’t work if :req-un contains and
or or
@ghadi @ben.borders
@ghadi You mean, someone trying to spec "everything"? I've seen some folks (new to spec) go down that path...
it’s useful to spec core data structures, boundaries, functions amenable to property testing
but it’s totally ok to not spec stuff, or use any? or ifn? etc to under-spec things that are still in process or too annoying to spec