This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-27
Channels
- # babashka (35)
- # beginners (85)
- # cider (14)
- # clojure (115)
- # clojure-europe (15)
- # clojure-norway (2)
- # clojure-portugal (9)
- # clojure-uk (3)
- # clojurescript (28)
- # conjure (35)
- # data-science (10)
- # datomic (4)
- # graalvm (28)
- # holy-lambda (7)
- # hyperfiddle (2)
- # jobs (2)
- # joker (4)
- # malli (9)
- # meander (6)
- # nbb (6)
- # off-topic (23)
- # pathom (3)
- # remote-jobs (1)
- # shadow-cljs (158)
- # sql (15)
- # tools-deps (35)
- # vim (5)
let's say I want to collect lists of matching patterns and also a map key at a higher level in a nested map. ie. given the following map:
{:a {:client "foo"
:items [{:x 1} 2 3]}
:b {:client "bar"
:items [{:x "q"} {:x "x"}]}}
I'd like to collect all values of maps with key :x
under :items
and also the value of :client
that appears alongside those :items
:
[["foo" [1] ["bar" ["q" "x"]]
What's a good way of doing this? Is it possible to generate that output with meander alone?I can get pretty close with the following:
(m/search {:a {:client "foo"
:items [{:x 1} 2 3]}
:b {:client "bar"
:items [{:x "q"} {:x "x"}]}
}
(m/$ {:client ?c
:items (m/scan {:x !i})})
[?c !i])
but it gives me pairs for each match rather than aggregating the !i
values:
(["foo" [1]] ["bar" ["q"]] ["bar" ["x"]])
(For more context, the map above is a simplified one; the actual map I want to extract the data from has a lot more levels of nesting under :items
before the :x
keys appear)