This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-31
Channels
- # aws (1)
- # beginners (82)
- # boot (7)
- # cider (1)
- # cljs-dev (13)
- # cljsrn (1)
- # clojure (37)
- # clojure-dev (5)
- # clojure-italy (5)
- # clojure-spec (9)
- # clojure-uk (8)
- # clojurescript (110)
- # community-development (6)
- # datomic (1)
- # devcards (1)
- # fulcro (12)
- # lein-figwheel (1)
- # off-topic (34)
- # portkey (24)
- # protorepl (25)
- # re-frame (4)
- # reagent (29)
- # shadow-cljs (8)
- # spacemacs (11)
- # specter (3)
- # unrepl (1)
- # vim (1)
how can i write a spec to validate a map like this: {[:type1 "args"] {:key-type1 value} [:type2 "args"] {:key-type2 value} ...(type-n)}
@gabriele.carrettoni First of all I would try to get the source of that data in a more workable format
E.g.
(def data [{:type 1
:args “args”
:value value}
{:type 2
:args “args”
:value value}])
And then you can spec that after transforming the awkwardly shaped data and verify if your normalization worked
@gabriele.carrettoni E.g.:
(def data {[:type1 "args"] {:key-type1 1}})
(defn transform-data
[data]
(for [[k v] data]
(let [[type-key args] k
other-key (keyword (str "key-"
(name type-key)))
value (get v other-key)]
{:type type-key
:args args
:value value})))
(transform-data data) ;;=> ({:type :type1, :args "args", :value 1})