This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-27
Channels
- # aleph (8)
- # announcements (14)
- # beginners (25)
- # cider (20)
- # cljdoc (5)
- # clojure (70)
- # clojure-europe (2)
- # clojure-germany (6)
- # clojure-italy (8)
- # clojure-nl (3)
- # clojure-russia (107)
- # clojure-spec (22)
- # clojure-uk (40)
- # clojurescript (18)
- # core-async (3)
- # cursive (8)
- # data-science (11)
- # datomic (20)
- # editors (1)
- # emacs (5)
- # figwheel-main (19)
- # fulcro (25)
- # graphql (1)
- # hoplon (2)
- # hyperfiddle (2)
- # jobs (1)
- # leiningen (3)
- # lumo (4)
- # off-topic (40)
- # pedestal (1)
- # quil (4)
- # re-frame (5)
- # shadow-cljs (105)
- # sql (4)
- # uncomplicate (1)
Hi All, I have been trying to write a spec recently and I can't quite describe what I want... I have a map where two sets of keys depend on each other like this:
{:a "string"
:b :value-b
:c :value-c}
or
{:a "string"
:b :value-not-b
:c :value-not-c}
and the :b
and :c
values depend on each other.( try three backticks to format that without emojis)
thank you @manutter51
I’m fairly shaky on spec still, but I’m thinking maybe you could take advantage of namespaced vs. unnamespaced keys, let me see if I can type up what I’m thinking
(s/def :any/a int?)
(s/def :is-value/b #{1 2 3})
(s/def :is-not-value/b #{4 5 6})
(s/def :is-value/c #{1 2 3})
(s/def :is-not-value/c #{4 5 6})
(s/def :is-or-not/my-map
(s/or :is (s/keys :req-un [:any/a :is-value/b :is-value/c])
:is-not (s/keys :req-un [:any/a :is-not-value/b :is-not-value/c])))
I’ve got a suspicion that won’t work, because maps are spec’ed by key, not by value, but a perverse part of my brain is saying maybe it would, because the keys are defined to take two mutually exclusive sets.
let me give that a try @manutter51
Generates seem like they’d be more likely to succeed, but I’m not as confident about conforms with “bad” data.
maybe, though? 🤞
well... I assume if it generates the correct data, then the other way round should work as well.
Thank you again @manutter51!!!
That’s pretty wild, I’ll have to remember that one myself.