This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-04
Channels
- # beginners (46)
- # boot (65)
- # cider (8)
- # cljs-dev (5)
- # cljsrn (4)
- # clojure (50)
- # clojure-conj (2)
- # clojure-france (1)
- # clojure-greece (18)
- # clojure-russia (8)
- # clojure-spec (39)
- # clojure-uk (36)
- # clojurescript (36)
- # clr (16)
- # component (2)
- # cursive (6)
- # datascript (3)
- # datomic (31)
- # devcards (2)
- # editors-rus (1)
- # emacs (15)
- # events (2)
- # figwheel (1)
- # funcool (24)
- # garden (3)
- # hoplon (22)
- # instaparse (15)
- # leiningen (3)
- # luminus (4)
- # om (59)
- # onyx (24)
- # overtone (1)
- # pedestal (3)
- # planck (18)
- # prelude (1)
- # protorepl (2)
- # re-frame (5)
- # rum (1)
- # sql (1)
- # uncomplicate (1)
- # untangled (66)
- # vim (18)
- # yada (4)
just wondering: why in multispec we have to repeat the dispatch fn/key in s/multi-spec call itself (since it's already in the defmulti definition)
as seen here: http://clojure.org/guides/spec#_multi_spec
You can use multispec on cases other than keyword maps too - in that case you need a fn for retagging instead.
Lets say I have two specs A and B and now I have a function that has a paramater that is the union of the two maps so like (keys ::A ::B). How would I define that spec?
@bfabry Ah, I did not know there was a spec/merge, thank you, I used the core one. With spec/merge it works 🙂
I'm feeling dumb. I have a map like
{:abc "abc" ; required key, and must have a value of "abc"
:x {:y nil ; required key, but value can be anything
:z 123 ; same as above}
}
(s/def :your/abc #{"abc"}) (s/def :your/x (s/keys :req-un [:your/y :your/z])) (s/def :your/y any?) (s/def :your/z any?) (s/keys :req-un [:your/abc :your/x])
(s/def ::abc "abc")
(s/def ::x (s/map-of :req-un [keyword? identity])
(s/def ::my-map (s/keys :req-un [::abc ::x]))
You can write a macro
If I have like 20 keys which are req-un in a map, all of which should have values checked of any?
, that seems like it should be more straightforward than resorting to doseq'ing to generate s/def
s
Sorry for the repost but, just to reiterate:
{
:abc "abc" ; required key, and must have a value of "abc"
:x {:y nil ; required key, but value can be anything
:z 123 ; same as above
:w :wow ; same as above
:o :out ; same as above
}
}