This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-30
Channels
- # aws (2)
- # beginners (139)
- # boot (9)
- # cider (1)
- # clara (2)
- # cljs-dev (35)
- # cljsrn (3)
- # clojure (112)
- # clojure-dusseldorf (9)
- # clojure-greece (6)
- # clojure-italy (13)
- # clojure-russia (160)
- # clojure-seattle-old (1)
- # clojure-uk (79)
- # clojurescript (85)
- # clojutre (1)
- # community-development (11)
- # core-async (32)
- # cryogen (2)
- # cursive (5)
- # data-science (16)
- # datomic (2)
- # events (1)
- # fulcro (29)
- # funcool (1)
- # graphql (4)
- # immutant (5)
- # instaparse (20)
- # jobs (2)
- # juxt (6)
- # leiningen (11)
- # luminus (21)
- # lumo (1)
- # off-topic (7)
- # onyx (20)
- # parinfer (33)
- # pedestal (4)
- # re-frame (41)
- # reagent (34)
- # ring-swagger (14)
- # rum (5)
- # spacemacs (9)
- # specter (11)
- # sql (14)
- # test-check (3)
- # yada (20)
I have a data structure like:
{:x
{:a {:y 1}
:b {:y 2}
:c {:y 3}}}
And I’d like {:a 1 :b 2 :c 3}
. I can write the select path that gets the values: [:x (sr/multi-path :a :b :c) :y]
, and I guess I can zipmap from there; but is there an elegant way to get specter to do that for me?sr/collect’ing the multi-path doesn’t really do what I expected:
[[[{:y 1} {:y 2} {:y 3}] nil]]
@lvh something like this? (select-any [:x (transformed MAP-VALS :y)] data)
Cool; thanks! I guess my sample was a little underspecified; there are other keys in there I do not want; but I guess a multi-path instead of a MAP-VALS would probably do the trick; lemme try
for that you will want multi-transform with keys you don't want becoming (terminal-val NONE)
and ones you do using (terminal :y)
if you want to do it in a one-liner that is
can also just do the select-any
followed by a (setval [MAP-KEYS #{:k1 :k2 ...}] NONE data2)
I would just do the latter since there's no multi-transformed
actually, just use submap
before transformed
that's the easiest and most efficient
[:x (submap [:k1 :k2...]) (transformed MAP-VALS :y)