This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-17
Channels
- # adventofcode (2)
- # beginners (153)
- # cider (14)
- # clara (9)
- # cljs-dev (8)
- # cljsjs (1)
- # cljsrn (4)
- # clojure (124)
- # clojure-dev (9)
- # clojure-france (18)
- # clojure-greece (22)
- # clojure-italy (11)
- # clojure-nlp (5)
- # clojure-russia (9)
- # clojure-spec (21)
- # clojure-uk (40)
- # clojurescript (82)
- # core-async (12)
- # cursive (3)
- # data-science (2)
- # datomic (225)
- # devcards (8)
- # docs (2)
- # duct (1)
- # emacs (18)
- # figwheel (2)
- # fulcro (117)
- # graphql (13)
- # hoplon (10)
- # jobs (7)
- # jobs-discuss (7)
- # keechma (8)
- # leiningen (4)
- # off-topic (16)
- # om (2)
- # om-next (3)
- # perun (11)
- # precept (4)
- # re-frame (24)
- # reagent (2)
- # remote-jobs (8)
- # ring (2)
- # ring-swagger (9)
- # rum (42)
- # shadow-cljs (8)
- # spacemacs (3)
- # specter (7)
- # uncomplicate (10)
- # unrepl (58)
- # yada (9)
Hey guys I have been scratching my head for some time now. I want to operate the following transformation :
["toto"
{:tag tag-to-unwrap :content ["titi" "tutu"]}
{:tag tag-to-unwrap :content ["toto"]}]
;=>
["toto" "titi" "tutu" "toto"]
Right now with:
(transform [ALL XML-ZIP NEXT-WALK NODE map? #(= :tag-to-unwrap (:tag %))]
:content
["toto"
{:tag tag-to-unwrap :content ["titi" "tutu"]}
{:tag tag-to-unwrap :content ["toto"]}])
I get
["toto" ["titi" "tutu"] ["toto"]]
Can I get specter to “splice” the vectors ["titi" "tutu"]
and ["toto"]
in the result?@jeremys with what's built-in you can do something like this:
(require '[com.rpl.specter.zipper :as z])
(def data
["toto"
{:tag :a :content ["titi" "tutu"]}
{:tag :a :content ["toto"]}]
)
(transform
[z/VECTOR-ZIP
z/DOWN
z/NEXT-WALK
(selected? z/NODE map?)
z/NODE-SEQ]
#(select [FIRST :content ALL] %)
data)
it's also pretty easy to make an ALL-SEQ
navigator which navigates to each element as a 1 element sequence, and then you could do:
(transform [ALL-SEQ (selected? FIRST map?)]
#(select [FIRST :content ALL] %)
data
)
technically this would work: (def ALL-SEQ (path z/VECTOR-ZIP z/DOWN z/NEXT-WALK z/NODE-SEQ))
though you could make it more efficient with a custom navigator
another solution:
(transform (continuous-subseqs map?)
#(select [ALL :content ALL] %)
data
)
Thx @nathanmarz I’ll take a look and see what I can come up with.