This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-25
Channels
- # admin-announcements (2)
- # beginners (36)
- # boot (37)
- # cider (65)
- # cljsrn (92)
- # clojars (3)
- # clojure (225)
- # clojure-austin (5)
- # clojure-belgium (2)
- # clojure-brasil (3)
- # clojure-china (1)
- # clojure-greece (2)
- # clojure-mexico (3)
- # clojure-news (2)
- # clojure-quebec (1)
- # clojure-russia (14)
- # clojure-spec (24)
- # clojure-uk (53)
- # clojurescript (34)
- # cursive (14)
- # datascript (9)
- # datomic (4)
- # defnpodcast (8)
- # devcards (30)
- # dirac (7)
- # editors (7)
- # emacs (1)
- # figwheel (1)
- # hoplon (85)
- # immutant (2)
- # incanter (1)
- # luminus (5)
- # off-topic (41)
- # om (18)
- # onyx (11)
- # perun (2)
- # re-frame (11)
- # reagent (9)
- # ring (3)
- # spacemacs (2)
- # spirituality-ethics (1)
- # test-check (19)
- # testing (12)
- # untangled (14)
- # yada (9)
I guess there’s no way to override that? The issue I’m running into is that merge assumes the key specs it gets are open for extension; so keys-excl merged with anything else fails to produce anything, because the keys-excl part of the spec that checks that the map only contains specific keys will fail on all the keys being added by anything that’s merged in
@alexmiller: last call in my clojure function is java (interop) fn call which returns void. So in clojure if java fn returns void we see nil, if i understand correctly.
Sometimes the intersection of two keys-excl
won't work either of course, since you have certain mandatory keys.
"closed" key sets seems like a common request, hopefully Rich reconsiders his choice here. I get that he doesn't want to make it the default, but simply providing a way to spec this can't hurt
There are no plans to revisit that afaik
@lvh you might try going down the path of treating your map as a coll-of tuple entries instead (make sure to use :into {})
Then merge that with s/keys to pick up the attribute checks
It's super easy to please everybody with a system with "closed" keysets by default (you can just add a k/v spec with any?
if you want to "open" the map), but that apparently is out of the question. I personally do not understand the logic here. Never saw anybody complain about the "strictness" of prismatic/Schema for these things for instance.
I mean, I guess I could, but that seems very gauche. What would that look like? I have a base spec that everything conforms to, and some stuff that’s specific per type (i.e. multi-spec)
@lvh:Yeah, you would remove keys. If a map-spec isn't open under extension, it may be open under specialization.
So provided that your map-specs s1
and s2
that have the form (keys-excl :opt [...] :opt-un [...])
then you could have
(defn intersection
[s1 s2]
(spec/with-gen (spec/and s1 s2)
#(fmap (fn [[a b]] (select-keys a (keys b)))
(spec/gen (spec/tuple s1 s2)))))
And you'd have the rule:
(valid? (intersection s1 s2) m)
; if and only if
(and (valid? s1 m) (valid? s2 m))
@mpenet: search slack history for @richhickey expounding on closed keysets making brittle systems
It's kind of in the same class as static vs dynamic lang/systems imho: it depends, sometimes exactitude is necessary. My point was that allowing both would do no harm, it would be optional.
it's not open for debate (IMHO) because it's a bad idea, and the core team can justify why