Fork me on GitHub
#specter
<
2017-09-06
>
dadair18:09:47

Hi again! Just trying to grasp navigation and collection a bit better. Let's say I have a recursive structure like so:

{:root {:name "/"
           :children {:a {:name "a" :children {<recursive>}}
                            :b {:name "b" :children {<recursive>}}}}}
I'd like to augment each "node" with the direct path to take to that node:
{:root {:name "/"
           :ref [:root]
           :children {:a {:name "a" :ref [:root :children :a] :children {<recursive>}}
                            :b {:name "b" :ref [:root :children :b] :children {<recursive>}}}}}
How would this work with mixing recursive-path and collect?

nathanmarz19:09:07

@dadair you can do that example like this:

(def data
 {:root {:name "/"
         :children {:a {:name "a"}
                    :b {:name "b"}}}})


(def nodes-with-path
  (recursive-path [] p
    (continue-then-stay
      (putval :children)
      (must :children)
      ALL
      (collect-one FIRST)
      LAST
      p)))

(transform [(putval :root) :root nodes-with-path :ref] (fn [& args] (butlast args)) data)

hmaurer19:09:17

@nathanmarz that’s very cool

hmaurer19:09:08

@nathanmarz completely uninformed question: are there similarities between Specter and Gremlin?

hmaurer19:09:20

(even though their intended use-cases are quite different)

nathanmarz20:09:28

@hmaurer I'm not very familiar with Gremlin

dadair20:09:50

thanks @nathanmarz that helps!