This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-03
Channels
- # bangalore-clj (1)
- # beginners (160)
- # boot (174)
- # cider (57)
- # cljs-dev (16)
- # cljsrn (5)
- # clojure (144)
- # clojure-argentina (1)
- # clojure-austin (6)
- # clojure-finland (2)
- # clojure-france (4)
- # clojure-russia (185)
- # clojure-serbia (4)
- # clojure-spec (61)
- # clojure-uk (126)
- # clojurescript (212)
- # community-development (7)
- # core-async (2)
- # cursive (17)
- # datomic (210)
- # emacs (10)
- # euroclojure (2)
- # gsoc (23)
- # hoplon (86)
- # jobs (8)
- # lein-figwheel (9)
- # luminus (19)
- # lumo (12)
- # off-topic (4)
- # om (14)
- # om-next (6)
- # pedestal (38)
- # perun (11)
- # planck (35)
- # portland-or (2)
- # ring (1)
- # ring-swagger (28)
- # specter (6)
- # untangled (6)
- # yada (2)
Is specter suited to transform clojure map keys?
{:a {:b {:c 123}} :d 456}
{:a_b_c 123 :d 456}
Something like that, back and forth.@nha you can do something like this:
user=> (def PATH-MAP-WALKER
#_=> (recursive-path [] p
#_=> (if-path map?
#_=> [ALL (collect-one FIRST) LAST p]
#_=> STAY
#_=> )))
#'user/PATH-MAP-WALKER
user=>
user=>
user=> (reduce
#_=> (fn [m path]
#_=> (assoc m (apply str (butlast path)) (last path)))
#_=> {}
#_=> (traverse PATH-MAP-WALKER {:a {:b {:c 1}} :d 2}))
{":a:b:c" 1, ":d" 2}
Nice 🙂 I don’t really understand the traverse part: it returns a function? Can I view it as a collection? (I am trying to make the reverse function now - but I am also just starting out with specter)
@nha traverse
is very efficient, there's no materialization of intermediate data structures (similar to transducers)