specter

richiardiandrea 2021-08-12T17:28:44.007400Z

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

richiardiandrea 2021-08-12T17:30:07.008800Z

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)

richiardiandrea 2021-08-12T17:31:22.009400Z

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)]))

nathanmarz 2021-08-12T20:54:57.010100Z

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

richiardiandrea 2021-08-12T20:55:42.010600Z

oooo it's that simple lol

nathanmarz 2021-08-12T20:55:57.011Z

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

richiardiandrea 2021-08-12T20:55:58.011100Z

oh wait

richiardiandrea 2021-08-12T20:56:15.011600Z

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

richiardiandrea 2021-08-12T20:56:35.012Z

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

nathanmarz 2021-08-12T20:57:03.012400Z

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

nathanmarz 2021-08-12T20:57:21.012700Z

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

richiardiandrea 2021-08-12T21:05:30.013600Z

@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

nathanmarz 2021-08-12T21:10:02.013800Z

that collect-one is in an independent path

nathanmarz 2021-08-12T21:10:20.014200Z

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

richiardiandrea 2021-08-12T21:15:40.015400Z

gotcha, like this?

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

richiardiandrea 2021-08-12T22:04:43.016300Z

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

richiardiandrea 2021-08-12T22:05:09.016700Z

I'll leave the duplication in the for now