This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-07
Channels
- # beginners (142)
- # boot (18)
- # cider (39)
- # cljs-dev (2)
- # cljsrn (11)
- # clojars (8)
- # clojure (51)
- # clojure-brasil (3)
- # clojure-italy (22)
- # clojure-losangeles (2)
- # clojure-nl (20)
- # clojure-nlp (2)
- # clojure-russia (4)
- # clojure-serbia (2)
- # clojure-spec (90)
- # clojure-uk (147)
- # clojurescript (116)
- # data-science (10)
- # datomic (189)
- # devcards (31)
- # duct (6)
- # emacs (12)
- # fulcro (16)
- # graphql (36)
- # juxt (1)
- # off-topic (5)
- # om (11)
- # overtone (2)
- # pedestal (4)
- # perun (1)
- # portkey (17)
- # reagent (6)
- # reitit (3)
- # shadow-cljs (57)
- # spacemacs (45)
- # specter (8)
- # tools-deps (46)
@sophiago it's a lot easier if your maps have more information about what they represent
this would be a way to do it, though it's not very efficient:
(def data {:baz "qux", :env [{:locals "foo" :k "v"} {:locals "bar"} {:baz "qux"}]})
(def MAP-NODES
(recursive-path [] p
(cond-path map? (stay-then-continue MAP-VALS p)
coll? [ALL p]
)))
(transform
[MAP-NODES
(not-selected?
MAP-VALS
MAP-NODES
(must :locals))]
#(select-keys % [:locals])
data)
Unfortunately, I don't have control over data representation in this case. But I think we're converging on something similar. I'm trying something like this: (setval [MAP-NODES #(and (not= :locals (first %)) (not (coll? (second %))))] NONE {:baz "qux", :env [{:locals "foo"} {:locals "bar"} {:baz "qux"}]})
this is a cleaner way to write that:
(setval
[MAP-NODES
ALL
(not-selected? FIRST (pred= :locals))
LAST
(complement coll?)]
NONE
data)
if you want to get rid of the empty map you can do this:
(def data {:baz "qux", :env [{:locals "foo" :k "v"} {:locals "bar"} {:baz "qux"}]})
(def MAP-NODES
(recursive-path [] p
(cond-path map? (stay-then-continue MAP-VALS p)
coll? [(compact ALL p)]
)))
(setval
[MAP-NODES
ALL
(not-selected? FIRST (pred= :locals))
LAST
(complement coll?)]
NONE
data)
Okay, yeah I think that's good enough I can follow it from here. compact
is being called on a keyword at some point in the traversal of a full ast, but I probably want to clean up the results further. Thanks yet again, @nathanmarz