This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-14
Channels
- # asami (1)
- # babashka (50)
- # beginners (70)
- # bristol-clojurians (6)
- # calva (36)
- # chlorine-clover (1)
- # cider (4)
- # clj-kondo (3)
- # cljdoc (49)
- # cljsrn (5)
- # clojure (96)
- # clojure-australia (3)
- # clojure-dev (1)
- # clojure-europe (84)
- # clojure-nl (4)
- # clojure-spec (9)
- # clojure-uk (65)
- # clojurescript (31)
- # community-development (6)
- # conjure (17)
- # cursive (8)
- # datascript (5)
- # datomic (12)
- # duct (3)
- # emacs (18)
- # figwheel-main (2)
- # fulcro (7)
- # helix (1)
- # jobs (3)
- # luminus (7)
- # off-topic (77)
- # pathom (3)
- # portal (1)
- # rdf (4)
- # re-frame (1)
- # reitit (4)
- # remote-jobs (4)
- # reveal (15)
- # rum (1)
- # sci (38)
- # shadow-cljs (22)
- # spacemacs (1)
- # specter (6)
- # sql (1)
- # test-check (1)
- # tools-deps (60)
- # vim (12)
(def map-walker
(recursive-path [] p
(cond-path
map?
[ALL p]
[vector? FIRST #(= % :c)]
LAST
[vector?]
[ALL p]
)))
(let [data {:a 1
:b [{:z 1 :c [1 2 3]}
{:c [{:d 1} {:e 1}]}]}]
(transform [map-walker] #(array-map :COUNTED (count %)) data))
The only downside is it would also transform a vector whose first element is :c as well
In reality there would never be such an element, because every vector has entities (maps) in it. Seems tricky compared to a solution not using specter. I honestly though the solution would be more straightforward than that. I just used being-counted-attributes
rather than #(= % :c)
, so #{:c}
. Thank you @UP90Q48J3.
Yeah, for such cases you can simply write a recursive function instead of using specter, or combine specter with a recursive helper function.
well, I think I finally managed to get Specter working in cljs bootstrap: https://github.com/redplanetlabs/specter/issues/72