This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-31
Channels
- # aleph (3)
- # aws (5)
- # beginners (65)
- # boot (17)
- # cljs-dev (112)
- # cljsrn (5)
- # clojure (146)
- # clojure-austin (3)
- # clojure-dusseldorf (3)
- # clojure-italy (18)
- # clojure-norway (13)
- # clojure-russia (84)
- # clojure-serbia (5)
- # clojure-spec (24)
- # clojure-uk (84)
- # clojurescript (204)
- # css (1)
- # cursive (21)
- # data-science (3)
- # datascript (21)
- # datomic (26)
- # emacs (5)
- # euroclojure (1)
- # hoplon (8)
- # jobs (7)
- # jobs-discuss (2)
- # keechma (35)
- # lumo (92)
- # mount (1)
- # nrepl (2)
- # numerical-computing (16)
- # off-topic (10)
- # om (58)
- # re-frame (13)
- # reagent (90)
- # remote-jobs (2)
- # ring-swagger (1)
- # spacemacs (9)
- # specter (6)
- # unrepl (17)
- # untangled (56)
- # yada (2)
If I have the following:
(def person
[{:name "Person", :id 1, :job "Something", :tag :a}
{:name "Person", :id 1, :job "Something", :tag :b}
{:name "Person", :id 1, :job "Something", :tag :c}])
I want to transform that to
{:name "Person", :id 1, :job "Something", :tag #{:c :b :a}}
In plain clojure I can do it with
(into {} (map (fn [[k v]] (assoc k :tag v)))
(reduce (fn [accum e]
(let [sm (select-keys e [:name :id :job])]
(if-let [exists (get accum sm)]
(assoc accum sm (conj exists (:tag e)))
(assoc accum sm #{(:tag e)}))))
{}
person))
I am hoping there's a nicer way to do the same in specter@danboykis that's computing an entirely new value, whereas specter is about changing part of a data structure
there are pieces of it you can make nicer with specter, like replacing the if-let
clause with (setval [(keypath sm) NONE-ELEM] (:tag e) accum)
@nathanmarz thanks for the explanation, I am new to specter and don't have a good feel for the its use cases yet
@nathanmarz figured it out: (specter/select (specter/walker is-pdf-attachment?) user/msg)