This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-07
Channels
- # beginners (166)
- # cider (6)
- # cljs-dev (12)
- # cljsrn (64)
- # clojure (71)
- # clojure-chicago (1)
- # clojure-spec (14)
- # clojure-uk (2)
- # clojurescript (25)
- # datomic (2)
- # docs (1)
- # duct (1)
- # emacs (4)
- # fulcro (5)
- # graphql (3)
- # java (46)
- # mount (5)
- # off-topic (29)
- # onyx (1)
- # portkey (10)
- # re-frame (12)
- # remote-jobs (1)
- # shadow-cljs (46)
- # spacemacs (1)
- # specter (4)
- # vim (2)
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"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.
@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)
ah, thank you @nathanmarz!