Fork me on GitHub
#specter
<
2024-04-05
>
J16:04:26

Hi guys! Is there a way to conditional path in multi-path ?

(def foo #{:a :b :c})

(s/multi-transform
  (s/multi-path
    (when (foo :a) [...]))
  {})

J19:04:08

cond-path check the current structure no? Because on the example above, I expected :foo #{}

(s/multi-transform
   (s/multi-path
    [:baz (s/terminal-val 1)]
    [(s/cond-path
      false [:foo s/NONE-ELEM (s/terminal-val 2)])])
   {:foo #{}})
;; => {:baz 1 :foo #{2}}

nathanmarz19:04:22

oh, if you literally just want the navigator itself to be determined by a non-structure related condition then you can use conditional in the path

nathanmarz19:04:50

the conditions in cond-path are "condition paths", which are considered true if they navigate to at least one value

nathanmarz19:04:00

the implicit navigator for a boolean is keypath, so the path false always navigates somewhere

nathanmarz19:04:05

in this case to the value nil

J20:04:19

Thanks nathan for the explanation. > you can use conditional in the path I miss something because a path like (s/multi-path (when false [...])) will fail and I got the error All navigation in multi-transform must end in 'terminal' navigators Maybe multi-transform doesn't allow this kind of stuff.

nathanmarz20:04:38

well, you still need a terminal navigator

nathanmarz20:04:45

but the path can be specified like that

nathanmarz20:04:12

(multi-path (if some-cond (term inc) STOP))

nathanmarz20:04:25

that would be one way to do it

J20:04:16

Aah yes! Thank you!