This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-19
Channels
- # announcements (6)
- # aws (10)
- # beginners (73)
- # bristol-clojurians (2)
- # calva (9)
- # cider (25)
- # clj-kondo (7)
- # clojure (160)
- # clojure-dev (2)
- # clojure-europe (63)
- # clojure-italy (7)
- # clojure-nl (10)
- # clojure-uk (76)
- # clojuredesign-podcast (6)
- # clojurescript (63)
- # cursive (6)
- # data-science (3)
- # datomic (26)
- # duct (59)
- # emacs (1)
- # fulcro (12)
- # graalvm (17)
- # hoplon (23)
- # jobs-discuss (2)
- # kaocha (6)
- # meander (7)
- # off-topic (3)
- # pathom (2)
- # rdf (68)
- # re-frame (12)
- # reagent (20)
- # reitit (5)
- # ring (3)
- # ring-swagger (1)
- # shadow-cljs (14)
- # spacemacs (10)
- # sql (3)
- # tools-deps (30)
- # yada (9)
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)})
👍 4
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.


