Fork me on GitHub

Hi! Is there a way in Meander to transform:

{:items {:item1 {:value 1}
         :item2 {:value 2}}}
{:values {:item1 1
          :item2 2}}
? I tried:
 {: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!


I came up with this:

  {: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:


Repeats in maps is a little ugly right now. That will be fixed with 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.


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)})

👍 4

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


🆒 Thank you for the help!


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

party-corgi 4
partywombat 4
parrot 8