This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-05
Channels
- # announcements (7)
- # beginners (10)
- # calva (14)
- # clj-otel (8)
- # clojure (42)
- # clojure-europe (20)
- # clojure-nl (1)
- # clojure-norway (22)
- # clojure-spec (8)
- # clojure-uk (7)
- # core-async (10)
- # cursive (1)
- # events (1)
- # hyperfiddle (20)
- # introduce-yourself (1)
- # jobs-discuss (11)
- # lsp (48)
- # missionary (3)
- # music (1)
- # off-topic (7)
- # overtone (9)
- # pedestal (21)
- # rdf (1)
- # releases (3)
- # shadow-cljs (22)
- # specter (13)
- # squint (1)
- # yamlscript (3)
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) [...]))
{})
@jean.boudet11 check out cond-path
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}}
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
the conditions in cond-path
are "condition paths", which are considered true if they navigate to at least one value
the implicit navigator for a boolean is keypath
, so the path false
always navigates somewhere
in this case to the value nil
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.
well, you still need a terminal navigator
but the path can be specified like that
(multi-path (if some-cond (term inc) STOP))
that would be one way to do it