Fork me on GitHub
#specter
<
2018-04-07
>
zlrth01:04:37

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

[{:user "matt"
  :docs [{:fulltext "the text"
          :url ""
          :fragments []}
         ;; more docs
         ]}
 ;; more maps
 ]
I want to update the data structure like so
[{:user "matt"
  :docs [{:fulltext "the text"
          :url ""
          :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"

zlrth01:04:26

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.

nathanmarz04:04:53

@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)