Fork me on GitHub
#specter
<
2017-10-31
>
eoliphant01:10:04

is there a something like a ‘move’ macro/operation? I’m picking my way through the use of recursive-path, etc. Basically, I’ve a use case where I need to find a node in a tree, save its current value, delete it from its current location, find a target node, then insert the saved node before or after the target. Once I get the recursive locator stuff working, it seems like I’d need a select and two transforms, or a select and a multi-transform, is that more or less correct?

nathanmarz02:10:51

best way to do something like that would be combining multi-transform and collect-one

nathanmarz02:10:24

depends on the use case though, some could require zippers

nathanmarz02:10:36

would need to see specifically what you're trying to do

eoliphant13:10:59

hi @nathanmarz sure, here’s a simplified example

(def fakeform {:formdef {:form/id 1
                         :form/groups [{:group/id 2
                                        :group/type :page
                                        :group/fields [{:field/id 3
                                                        :field/name :fieldone}
                                                       {:field/id 4
                                                        :field/name :fieldtwo}
                                                       {:field/id 5
                                                        :field/name :fieldthree}]
                                        :group/subgroups  [{:group/id 6
                                                            :group/type :section
                                                            :group/fields [{:field/id 7
                                                                            :field/name :fieldfour}]}]}]}})
I’d like to approach simple transforms like “move the map identified by :field/id 3 after the one identified by :field/id 4” (which I can do with a srange/reverse, etc) as well as more arbitrarily complex ones like “move the map identified by :field/id 3 after the one identified by :field/id 7” in a consistent manner

nathanmarz14:10:57

@eoliphant you can do this with a helper path that navigates you to a zipper pointing to the desired node

nathanmarz14:10:05

(point-to 3)

nathanmarz14:10:33

then you could do (select-any [(point-to 3) zip/NODE] fakeform) to get the value for 3

nathanmarz14:10:54

(setval [(point-to 3) zip/NODE-SEQ] [] fakeform) to remove 3

nathanmarz14:10:50

and (setval [(point-to 7] zip/INNER-RIGHT] [value-for-3] fakeform) to finish the move

nathanmarz14:10:12

actually you could combine the retrieval of 3's value with removal using replace-in

eoliphant14:10:52

Ok will give that a shot, so point-to will be my recursive-path based helper?

eoliphant14:10:39

gotcha, will play around with it