This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-16
Channels
- # atlanta-clojurians (1)
- # aws (1)
- # beginners (65)
- # boot (4)
- # cider (81)
- # cljs-dev (25)
- # cljsrn (27)
- # clojure (129)
- # clojure-dusseldorf (12)
- # clojure-italy (68)
- # clojure-norway (5)
- # clojure-poland (4)
- # clojure-spec (14)
- # clojure-uk (72)
- # clojurescript (144)
- # code-reviews (19)
- # copenhagen-clojurians (5)
- # cursive (16)
- # datomic (21)
- # editors (1)
- # emacs (15)
- # events (1)
- # figwheel (6)
- # fulcro (54)
- # graphql (1)
- # hoplon (24)
- # jobs (6)
- # jobs-discuss (2)
- # keechma (4)
- # leiningen (6)
- # luminus (17)
- # lumo (2)
- # off-topic (43)
- # onyx (6)
- # pedestal (2)
- # perun (2)
- # portkey (3)
- # re-frame (22)
- # reagent (11)
- # ring-swagger (5)
- # shadow-cljs (46)
- # specter (8)
- # test-check (2)
- # testing (3)
- # vim (16)
- # yada (1)
I have a lot of cases in my code where I destructure the input of a function using a spec and then extract the keys using a long vector that’s basically the exact same as the spec itself. Is there a way to just use a spec to destructure keys?
in other languages you have like a splat
or explode
that would give you all of the keys as vars in the current scope. I get that it would be a bad idea, but with a spec your still explicit
@seancorfield wrote a macro but I wanted it to do without writing my own let macro
I wrote a macro that uses the registry to return a vector with the keys, and use that in combination with C-c C-v C-w
eval and replace in the editor. Of course there is some potential erosion as you'd need to maintain it in multiple places. But at least it's explicit.
I'm still working out where to put specs in my project. I'm coming from test-driven development so it seems natural to put fdef
s in test namespaces: define what the function should do, separate from the implementation. But then again, does that mean that code that calls the function won't have loaded those specs and will be missing out on the benefits? I'm curious how people are organizing their projects.
I tend to put the fdef
right before the defn
. That provides the most documentation benefits IMO and also anyone who loads my code is guaranteed to get the specs if they want to instrument them
As you noted, if you put them in test namespaces, then clients will need to load both namespaces in order to instrument, which I think would be surprising
@mathpunk use :clojure.spec.test.check/opts
For some reason they missed to alpha it