specter

itaied 2023-12-04T10:37:40.897049Z

Given the following tree:

{:children [:a {:children [:aa {:children [:aa {}]}]}
                           :b {:children [:bb {}]}]}
I'm trying to add a hashed id of the path of each element. That's the path I wrote:
(def a
  (sp/recursive-path [] p
                     [(sp/must :children)
                      (sp/view (partial partition 2))
                      sp/ALL
                      (sp/collect-one sp/FIRST)
                      sp/LAST
                      (sp/stay-then-continue p)]))
it works as expected for select with collected values:
(sp/select a {:children [:a {:children [:aa {}]}
                           :b {:children [:bb {}]}]})
=> [[:a {:children [:aa {}]}] [:a :aa {}] [:b {:children [:bb {}]}] [:b :bb {}]]
But when transformed, it changes the vector type of :children to nested lists (probably because of the sp/view?)
(sp/transform a
                (fn [& args] (let [o (last args)
                                   h-id (-> args butlast hash)]
                               (-> o
                                   (assoc :h-id h-id))))
                {:children [:a {:children [:aa {}]}
                            :b {:children [:bb {}]}]})
=> {:children ((:a {:children ((:aa {:h-id -149183532})), :h-id -237810920}) (:b {:children ((:bb {:h-id -876750745})), :h-id -1995900215}))}
How can I modify a view back to its original value? When I'm printing o inside the transform function, the children is a valid vector and not a nested list

rolt 2023-12-05T11:04:39.613509Z

did you try using parser ?

rolt 2023-12-05T11:06:37.414929Z

(parser #(partition 2 %) #(into [] (mapcat identity) %)) instead of view

itaied 2023-12-05T12:46:24.093599Z

thanks ill give it a shot