Fork me on GitHub
#specter
<
2021-08-12
>
richiardiandrea17:08:44

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

richiardiandrea17:08:07

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)

richiardiandrea17:08:22

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

nathanmarz20:08:57

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

richiardiandrea20:08:42

oooo it's that simple lol

nathanmarz20:08:57

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

richiardiandrea20:08:15

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

richiardiandrea20:08:35

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

nathanmarz20:08:03

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

nathanmarz20:08:21

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

richiardiandrea21:08:30

@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

nathanmarz21:08:02

that collect-one is in an independent path

nathanmarz21:08:20

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

richiardiandrea21:08:40

gotcha, like this?

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

richiardiandrea22:08:43

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

richiardiandrea22:08:09

I'll leave the duplication in the for now