This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-15
Channels
- # announcements (13)
- # aws (6)
- # babashka (23)
- # babashka-sci-dev (6)
- # beginners (64)
- # calva (110)
- # cider (25)
- # cljs-dev (5)
- # cljsrn (8)
- # clojars (5)
- # clojure (20)
- # clojure-austin (1)
- # clojure-europe (77)
- # clojure-nl (1)
- # clojure-uk (3)
- # clojurescript (14)
- # cursive (7)
- # datahike (9)
- # datomic (13)
- # eastwood (15)
- # emacs (14)
- # figwheel-main (1)
- # fulcro (8)
- # graalvm-mobile (2)
- # graphql (2)
- # honeysql (2)
- # hyperfiddle (2)
- # introduce-yourself (4)
- # jobs (4)
- # joyride (4)
- # leiningen (4)
- # lsp (8)
- # minecraft (8)
- # off-topic (11)
- # polylith (18)
- # rdf (2)
- # reagent (3)
- # reitit (4)
- # remote-jobs (1)
- # shadow-cljs (39)
- # specter (7)
- # xtdb (3)
I have a OpenAPI JSON file that I am trying to process. The resulting structure is not very clear to me, it looks like a nested collections and maps with no uniformity. Fortunately every node that I am interested has unique identifier. Is there a way to do a deep-search and extract the object at its place. I have tried [MAP-VALS ALL MAP-VALS key-pred] but it fails because the structure is not uniform. I trying to avoid the need to write specific navigators because I am sure I will miss a particular path.
if there are different levels of nesting, you can have a look at https://github.com/redplanetlabs/specter/wiki/Using-Specter-Recursively
disclaimer: i barely ever used specter with recursion, I'd probably use clojure.walk or clojure.zip for this kind of things
you need the walker
navigator https://github.com/redplanetlabs/specter/wiki/List-of-Navigators#walker
Is there a better way to write this:
(defn get-element [id model]
(let [id-match? #(= (:id %) id)]
(or (select-one [:model :people ALL id-match?] model)
(select-one [:model :softwareSystems ALL id-match?] model)
(select-one [:model :softwareSystems ALL :containers ALL id-match?] model)
(select-one [:model :softwareSystems ALL :containers ALL :components ALL id-match?] model))))
a single select-one
with https://github.com/redplanetlabs/specter/wiki/List-of-Navigators#multi-path maybe ?