specter

Latest version: 1.1.3
zlrth 2018-04-07T01:41:37.000119Z

I have a datastructure that's a combination of maps and vectors, with various amounts of nesting:

[{:user "matt"
  :docs [{:fulltext "the text"
          :url "<http://www.google.com|www.google.com>"
          :fragments []}
         ;; more docs
         ]}
 ;; more maps
 ]
I want to update the data structure like so
[{:user "matt"
  :docs [{:fulltext "the text"
          :url "<http://www.google.com|www.google.com>"
          :fragments [{:date "2018" :text "the "}
                      {:date "2017" :text "text"}]}
         ;; more docs
         ]}
 ;; more maps
 ]
I want to do: "select the map with the key-value pair :user and "matt", then in the :doc vector, select the map with the kv pair :fulltext and "the text" and conj these two maps"

zlrth 2018-04-07T01:52:26.000039Z

I skimmed the Navigators docs, and couldn't find "select the map containing the kv-pair." I suspect that I'm trying to do something not idiomatic. In theory, I could make this data structure entirely out of nested maps--then this would be trivial--but i don't know if i can guarantee that a map will have a unique key.

nathanmarz 2018-04-07T04:09:53.000068Z

@mfm looks like this:

(defn map-with-kv [k v]
  (path ALL #(= v (get % k))))

(setval
  [(map-with-kv :user "matt")
   :docs
   (map-with-kv :fulltext "the text")
   :fragments
   END
   ]
  [{:date "2018" :text "the "}
   {:date "2017" :text "text"}]
  data)

zlrth 2018-04-07T12:17:16.000028Z

ah, thank you @nathanmarz!