Fork me on GitHub
#specter
<
2018-01-13
>
mbjarland22:01:47

how would I move a piece of a data structure (nested maps and vectors) from one path to another? Seems transform points at a path and changes the value at that path using a function. Would it be a select followed by a setval or is there a one-liner?

mbjarland22:01:07

let me rephrase that because the case is more complex, how would I go from:

{:layout    [{:repeat [:a]}
             {:delim [" "]}
             {:repeat [:b]}],
 :apply-for [:odd :even]}
to
{:layout    [{:repeat [:a] :apply-for :odd}
             {:delim [" "]}
             {:repeat [:b] :apply-for :even}]}
where there are as many elements in the :apply-for vector as there are :repeat maps in be before structure. So we are matching by index and moving the :odd and :even to the corresponding :repeat map

mbjarland22:01:05

I get the feeling I might have to select the vector and then do a stateful transform call where the transform function would pull items from the vector one-by-one, but let me know if there is some better way

nathanmarz23:01:48

(let [af (:apply-for data)]
  (->> data
       (setval [:layout
                (subselect
                  ALL
                  #(contains? % :repeat)
                  :apply-for)
                ]
                af)
       (setval :apply-for NONE)
       ))