specter

Latest version: 1.1.3
2020-06-05T23:26:58.059200Z

Can I use spectre to recursively transform java.util.HashMap of java.util.HashMaps to regular clojure maps?

2020-06-05T23:44:37.059800Z

I'm basically trying to go from the top here, where all the maps are java.util.HashMap, to the bottom, where all maps are IAssociative:

{"name" "foo"
 "children" {"bar" {"name" "bar"
                    "children" {}}
             "baz" {"name" "baz"
                    "children" {"quux" {"name" "quux"
                                        "children" {}}}}}}

;;=> (addition of `ref`, keywordize the keys, make standard IAssociative)

{:name "foo"
 :children {:bar {:name "bar"
                  :children {}
                  :ref "foo/bar"}
            :baz {:name "baz"
                  :children {:quux {:name "quux"
                                    :children {}
                                    :ref "foo/baz/quux"}}
                  :ref "foo/baz"}}
 :ref "foo"}

2020-06-05T23:45:05.060200Z

Had an implementation using both clojure.walk and spectre, but want to do it in 1 pass, if possible

2020-06-05T23:51:42.060800Z

I can select each with:

(def HASH-MAPS
    (sp/recursive-path
     []
     p
     (sp/stay-then-continue
      (sp/must "children")
      sp/MAP-VALS
      p)))

  (clojure.pprint/pprint
   (sp/select
    [:root HASH-MAPS]
    {:root hm}))

2020-06-05T23:51:55.061200Z

It's the transform in one pass that's getting me confused >.<