meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
niclasnilsson 2020-03-24T21:16:59.036300Z

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.

noprompt 2020-03-24T21:32:48.038300Z

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

noprompt 2020-03-24T21:38:30.038600Z

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

noprompt 2020-03-24T21:39:46.039600Z

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

noprompt 2020-03-24T21:42:42.041400Z

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

niclasnilsson 2020-03-24T22:02:24.042100Z

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

noprompt 2020-03-24T22:07:43.042500Z

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