specter

J 2024-04-05T16:13:26.260609Z

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) [...]))
  {})

nathanmarz 2024-04-05T17:39:06.522819Z

@jean.boudet11 check out cond-path

J 2024-04-05T19:44:08.986449Z

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}}

nathanmarz 2024-04-05T19:49:22.270439Z

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

nathanmarz 2024-04-05T19:49:50.859249Z

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

nathanmarz 2024-04-05T19:51:00.167429Z

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

nathanmarz 2024-04-05T19:51:05.982289Z

in this case to the value nil

J 2024-04-05T20:01:19.493809Z

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.

nathanmarz 2024-04-05T20:02:38.324019Z

well, you still need a terminal navigator

nathanmarz 2024-04-05T20:02:45.922319Z

but the path can be specified like that

nathanmarz 2024-04-05T20:03:12.720819Z

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

nathanmarz 2024-04-05T20:03:25.174639Z

that would be one way to do it

J 2024-04-05T20:04:16.973609Z

Aah yes! Thank you!