meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
jimmy 2020-03-19T04:27:39.293Z

Pushed a fix, will cut a release tomorrow.

2020-03-19T15:45:05.293700Z

Hi! Is there a way in Meander to transform:

{:items {:item1 {:value 1}
         :item2 {:value 2}}}
into:
{:values {:item1 1
          :item2 2}}
? I tried:
(m/search
 {:items {:item1 {:value 1}
          :item2 {:value 2}}}
 {:items {?item {:value ?value}}}
 {:values {?item ?value}})
But I get:
({:values {:item2 2}} {:values {:item1 1}})
I also tried match (which complains of logic variables in the key position) and rewrite, but could not figure out a way. I know I can do a merge-with on top of the result, but curious if there is a way to do this directly with Meander. Thanks!

magnusdk 2020-03-19T15:56:40.293800Z

I came up with this:

(m/match
  {:items {:item1 {:value 1}
           :item2 {:value 2}
           :item3 {:value 3}}}
  {:items (m/seqable [!item {:value !value}] ...)}
  {:values (zipmap !item !value)})
but I’m still new to Meander so I can’t tell if this is the most idiomatic way or not :man-shrugging:

jimmy 2020-03-19T16:05:45.294100Z

Repeats in maps is a little ugly right now. That will be fixed with https://github.com/noprompt/meander/pull/117 But in the mean time you can do this

(m/rewrite {:items {:item1 {:value 1}
                    :item2 {:value 2}}}
  {:items {& (m/seqable [!ks {:value !vs}] ...)}}
  {:values {& [[!ks !vs] ...]}})
I can explain this in more detail later.

jimmy 2020-03-19T16:18:26.294400Z

Once this lands all you'd have to do is.

(m/rewrite {:items {:item1 {:value 1}
                    :item2 {:value 2}}}
  {:items (m/map-of !ks {:value !vs})}
  {:values (m/map-of !ks !vs)})

πŸ‘ 1
jimmy 2020-03-19T20:28:50.294700Z

This has now been merged if you update your meander to β€œ0.0.408” you can now use map-of

jimmy 2020-03-19T20:32:10.296800Z

New version: meander/epsilon {:mvn/version "0.0.408"} * Adds map-of operator. * Removes clojurescript dependency * Fixes a bug in a :ret spec.

🦜 2
1
1
2020-03-19T21:04:12.296900Z

πŸ†’ Thank you for the help!