Fork me on GitHub
#meander
<
2020-03-24
>
niclasnilsson21:03:59

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.

noprompt21:03:48

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

noprompt21:03:30

(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}]}

noprompt21:03:46

(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}]}

noprompt21:03:42

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

niclasnilsson22:03:24

Thanks, that was much, much nicer that what we had. Will try this on deeper nested maps as well.

noprompt22:03:43

No problem. I’m here to help if I can. 🙂