This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-15
Channels
- # beginners (97)
- # boot (54)
- # cider (13)
- # cljs-dev (3)
- # cljsrn (9)
- # clojure (64)
- # clojure-berlin (1)
- # clojure-brasil (119)
- # clojure-dev (3)
- # clojure-france (5)
- # clojure-greece (1)
- # clojure-italy (5)
- # clojure-madison (1)
- # clojure-russia (15)
- # clojure-spec (25)
- # clojure-uk (57)
- # clojurebridge (5)
- # clojurescript (45)
- # code-art (1)
- # community-development (17)
- # cursive (24)
- # datomic (83)
- # emacs (11)
- # fulcro (70)
- # hoplon (7)
- # immutant (3)
- # leiningen (19)
- # luminus (5)
- # lumo (25)
- # onyx (123)
- # other-languages (7)
- # pedestal (2)
- # re-frame (12)
- # ring (15)
- # ring-swagger (51)
- # shadow-cljs (89)
- # spacemacs (23)
- # sql (4)
- # unrepl (57)
- # utah-clojurians (1)
- # vim (1)
@ajmagnifico something to consider, Spec also recommends flat maps:
{:cnx-info.source.db/host :env/DB_HOST :cnx-info.source.db/port :env/DB_PORT :cnx-info.dst.db/host "localhost" ... :job/dir "some-directory}
@tbaldridge interesting, is that implicit in its design, or did I miss that recommendation somewhere?
https://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/map-of
(s/map-of int? map?)
but you could get more specific (s/map-of int? ::some-complex-keys-spec)
thanks @tbaldridge. That’s a really good idea, and it will actually solve a couple of other problems for me as well. I didn’t recall that keyword namespaces don’t actually need to correspond to real namespaces, even though that’s exactly what taylor told me! I guess I just needed to see it concretely for it to click.
I guess the only thing you miss out on when you make up namespaces is use of the ::
syntax
but in my case, that’s a small price to pay
I'm trying to spec a variadic function that has a gnarly java-esque method signature like (f str int)
(f str int bool)
(f str int bool int)
. I've tried to model this w/ s/cat but I'm having trouble building a spec that says (f str int int)
is invalid but (f str int bool int)
is valid. Example:
(s/def ::foo (s/cat :a string? :b int? :c (s/nilable boolean?) :d (s/nilable int?)))
this works if args are supplied as nil. but I can't figure out how to also support the smaller arg list. (s/valid? ::foo ["a" 1])
is false
Other suggestions were fine but also could use nested s/? for optional stuff
Something like this?
(s/def ::foo (s/cat :a string? :b int? :opts (s/? (s/cat :c boolean? :opts (s/? (s/cat :d? int?))))))
like (s/def ::foo (s/alt :two-arg-version (s/cat :a string? :b int) :three-arg-version (s/cat :a string? :b int? :c boolean?) ...etc)
@U1NCSDGDQ in my haste I forgot to include s/cat
in the mix