specter

Latest version: 1.1.3
mbjarland 2018-01-13T22:49:47.000018Z

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?

mbjarland 2018-01-13T22:57:07.000046Z

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

mbjarland 2018-01-13T22:59:05.000027Z

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

nathanmarz 2018-01-13T23:36:35.000084Z

@mbjarland use subselect

nathanmarz 2018-01-13T23:36:48.000045Z

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