This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-24
Channels
- # announcements (10)
- # aws-lambda (9)
- # babashka (14)
- # beginners (166)
- # calva (63)
- # chlorine-clover (4)
- # cider (40)
- # cljs-dev (4)
- # clojure (182)
- # clojure-europe (18)
- # clojure-italy (5)
- # clojure-nl (5)
- # clojure-spec (17)
- # clojure-uk (55)
- # clojurescript (11)
- # core-async (12)
- # cursive (23)
- # datascript (5)
- # datomic (19)
- # emacs (4)
- # fulcro (46)
- # graalvm (2)
- # hoplon (2)
- # joker (3)
- # juxt (1)
- # keechma (2)
- # leiningen (20)
- # malli (1)
- # meander (7)
- # nrepl (1)
- # off-topic (72)
- # pedestal (6)
- # re-frame (15)
- # reitit (7)
- # shadow-cljs (34)
- # sql (14)
- # testing (14)
- # tools-deps (11)
- # tree-sitter (1)
- # vim (14)
- # xtdb (19)
- # yada (3)
The … and lists are kind of apparent, but I don’t get how to use something similar with maps. If I have an input like
{:properties {:a {:type :int} :b {:type :string}}
and want the result
{:properties
[{:name :a :type :int} {:name :b :type :string}]}
What would be idiomatic meander way of doing that? The … is not apparent to me how to use in the map case. Using search, we’d get one {:properties [ . . .] } structure per property, instead of a map.We just added map-of and sub map-of operators but you can also use seqable if you’re not in a situation to have multiple solutions
(m/rewrite {:properties {:a {:type :int} :b {:type :string}}}
{:properties (m/map-of !name {:type !type})}
{:properties [{:name !name, :type !type} ...]})
;; =>
{:properties [{:name :a, :type :int} {:name :b, :type :string}]}
(m/rewrite {:properties {:a {:type :int} :b {:type :string}}}
{:properties (m/seqable [!name {:type !type}] ...)}
{:properties [{:name !name, :type !type} ...]})
;; =>
{:properties [{:name :a, :type :int} {:name :b, :type :string}]}
One thing we haven’t gotten around to doing is making the
{& [[k v] ...]}
syntax work for pattern matching. It works for substitution due to the fact that &
is works like into
Thanks, that was much, much nicer that what we had. Will try this on deeper nested maps as well.