This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-31
Channels
- # announcements (3)
- # beginners (139)
- # boot (28)
- # cider (40)
- # cljdoc (1)
- # cljs-dev (30)
- # clojure (61)
- # clojure-conj (1)
- # clojure-dev (113)
- # clojure-germany (4)
- # clojure-italy (29)
- # clojure-nl (3)
- # clojure-russia (2)
- # clojure-spec (38)
- # clojure-uk (53)
- # clojurescript (188)
- # core-async (4)
- # css (2)
- # cursive (7)
- # data-science (5)
- # datomic (14)
- # emacs (1)
- # figwheel-main (192)
- # fulcro (37)
- # jobs-discuss (1)
- # mount (4)
- # off-topic (47)
- # pedestal (7)
- # portkey (14)
- # re-frame (4)
- # reagent (22)
- # reitit (2)
- # remote-jobs (1)
- # ring (6)
- # shadow-cljs (65)
- # spacemacs (7)
- # specter (6)
- # yada (8)
hmm, interesting. I'm trying to select the meta from some objects and use that in a transformation step. It seems like when I put meta in the path, it acts as an identity function, returning the same values
Okay. So, for each element in this collection, I want to take its metadata key if it has metadata, or the key will be in a map as the second element of the list. so, data looks like this:
[^{:key "hello"} [:div]
[:div {:key "world"}]
[:div [:subdiv]]]
I want to select the keys, if they exist, for each. So, something like
(s/select
[s/ALL
(s/if-path [s/META :key]
[s/META :key]
[#(< 1 (count %)) (s/nthpath 1) map? :key])]
[^{:key "hello"} [:div]
[:div {:key "world"}]
[:div [:subdiv]]])
=> ["hello" "world" nil]
but if-path isn't doing what I thought. if-path tests the first element, and if it succeeds, uses that path for all of the elements.
How do I do what I'm trying to do?