specter

Latest version: 1.1.3
2018-08-31T15:29:24.000100Z

I figured it out!

idiomancy 2018-08-31T21:43:40.000100Z

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

idiomancy 2018-08-31T21:47:02.000100Z

oh, I see. there's a specific META navigator

idiomancy 2018-08-31T22:28:34.000100Z

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?

idiomancy 2018-08-31T22:44:58.000100Z

I ended up doing it with a multi-path and a filter for now... is there a better way?

idiomancy 2018-08-31T22:46:32.000100Z

[s/ALL
 (s/multi-path [s/META :key]
               [#(< 1 (count %))
                (s/nthpath 1)
                map? :key])
 some?]
and then I just manually select the first element of the path returned collect, because I don't know how to bring it back to a single element 😂