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.
No problem. I’m here to help if I can. 🙂