Pushed a fix, will cut a release tomorrow.
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!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: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.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)})
This has now been merged if you update your meander to β0.0.408β you can now use map-of
New version: meander/epsilon {:mvn/version "0.0.408"}
* Adds map-of operator.
* Removes clojurescript dependency
* Fixes a bug in a :ret spec.
π Thank you for the help!