specter 2021-08-12

Hi folks, a question - can a multi-path share a path between its entries or in other words, can I cascade multi-paths?

can I need to do some transformation at the top level but also many more that are recursive and would not like to duplicate paths (it's nice that multi-transform allows me to share but I can't share the recursive path I want to use)

basically I would like to avoid repeating POST-ORDER-VALS below

(sp/multi-transform (sp/multi-path [(sp/map-key :measurement-definition/type) (sp/terminal-val :measurement-type)]
                                      [(sp/collect-one (sp/must :measurement-definition/legacy)
                                                       (sp/must :measurement-definition/api)
                                                       (sp/must :measurement-definition/unit))
                                       (sp/must :measurement-definition/unit)
                                       (sp/terminal (fn [current-unit collected-unit] (println "!!!" current-unit collected-unit) (or current-unit collected-unit)))]
                                      [lib.specter/POST-ORDER-VALS lib.specter/MAP-KEY-NAMESPACES (sp/terminal sp/NONE)]
                                      [lib.specter/POST-ORDER-VALS lib.specter/EMPTY-SEQUENCE (sp/terminal sp/NONE)]
                                      [lib.specter/POST-ORDER-VALS sp/MAP-VALS nil? (sp/terminal-val sp/NONE)]))

@richiardiandrea you can combine those three paths into [POST-ORDER-VALS (multi-path [MAP-KEY-NAMESPACES ...] [EMPTY-SEQUENCE ...] [MAP-VALS ...]]

oooo it's that simple lol

not strictly the same if the first path changes what POST-ORDER-VALS does, but it's probably what you need

oh wait

yeah I tried that and it won't work for sp/collect-one

cause it will do post order and collect twice if I understand correctly

do you have collect-one inside POST-ORDER-VALS or your other custom navs?

as written here those three paths don't appear to have any value collection

@nathanmarz well I am collecting a nested key from the top of the tree - that's why I left it out from the recursive navigator

that collect-one is in an independent path

it needs to be collected at the start of combining those three paths

gotcha, like this?

(sp/multi-transform [(sp/collect-one (sp/must :measurement-definition/legacy) ...)
                     POST-ORDER-VALS
                     ...
I will try that out, thanks!

yeah the problem with putting it at the top of the path is that all the terminal will be called with two (or more) collected params

I'll leave the duplication in the for now