This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-24
Channels
- # announcements (5)
- # aws (24)
- # babashka (41)
- # beginners (130)
- # bristol-clojurians (2)
- # calva (39)
- # chlorine-clover (64)
- # cider (30)
- # clojure (202)
- # clojure-belgium (1)
- # clojure-dev (99)
- # clojure-europe (5)
- # clojure-hungary (4)
- # clojure-italy (10)
- # clojure-losangeles (8)
- # clojure-nl (11)
- # clojure-norway (6)
- # clojure-spec (7)
- # clojure-uk (12)
- # clojurescript (52)
- # core-typed (26)
- # cursive (19)
- # data-science (19)
- # datomic (19)
- # duct (10)
- # emacs (17)
- # fulcro (22)
- # graalvm (11)
- # jobs (3)
- # kaocha (28)
- # leiningen (6)
- # lumo (2)
- # malli (10)
- # nrepl (2)
- # off-topic (23)
- # pathom (2)
- # pedestal (7)
- # re-frame (3)
- # reagent (30)
- # reitit (2)
- # remote-jobs (2)
- # shadow-cljs (77)
- # sql (10)
- # test-check (22)
- # tools-deps (37)
- # vscode (1)
- # yada (3)
When conforming a sequence spec, can we guaranty key order? For instance:
(s/def ::a neg-int?)
(s/def ::b zero?)
(s/def ::c pos-int?)
(s/def ::sequence (s/cat :a ::a, :(s/? ::b), :c ::c))
I would like to use conform
to know if the second element of the sequence is :b
or :c
(labels given in cat
). conform
returns a clojure.lang.PersistentHashMap
, which does not key the keys in the same order as in the sequence.s/tuple is a better match
s/conform
just tells you how it matched. If you call s/valid?
and get true
then the input sequence is valid as is.
I would have liked to use conform
to parse the sequence and end up with {:a -2, :c 10}
Spec isn't really a "parser" but if you know your elements should be in a given order, you can easily manipulate the data you get from s/conform
to produce a more appropriate structure.
(you know you're going to get :a
first and :c
last so the only question is (contains? conformed-data :b)
to see if a zero is present...
ok thanks for your help!