This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-22
Channels
- # beginners (104)
- # bitcoin (1)
- # boot (5)
- # clara (3)
- # cljs-dev (14)
- # cljsjs (5)
- # cljsrn (1)
- # clojure (242)
- # clojure-italy (17)
- # clojure-news (13)
- # clojure-norway (3)
- # clojure-russia (101)
- # clojure-spec (41)
- # clojure-uk (87)
- # clojurescript (38)
- # core-async (38)
- # cursive (6)
- # datomic (11)
- # defnpodcast (3)
- # docs (14)
- # editors (8)
- # events (1)
- # fulcro (7)
- # hoplon (25)
- # leiningen (4)
- # luminus (7)
- # off-topic (25)
- # onyx (1)
- # portkey (14)
- # random (1)
- # re-frame (7)
- # reagent (4)
- # rum (4)
- # schema (8)
- # shadow-cljs (257)
- # spacemacs (10)
- # specter (4)
- # unrepl (3)
- # yada (1)
I have a recursive-path walker in the works, but I am hitting a not on a particular prismatic/shema record. In particular, s/if
returns a record with two paths I would like to explore (say, left and right). I know how to extract them from the record but not how to navigate to both of them:
(def ^:private PATH-SCHEMA-WALKER
(recursive-path [] p
(cond-path
(fn [v]
(instance? schema.core.ConditionalSchema v))
[ALL (collect-one FIRST) LAST p] ;; how do I walk left and right here?
(fn [v]
(cond
(primitive-schema? v) false
(map? v) true ;; this is a real path
:default false))
[ALL (collect-one FIRST) LAST p]
(fn [v] true) STAY)))
Here is my attempt above, but I don't know what to put for the first path. Here is how I can extract the schemas:
(if (instance? schema.core.ConditionalSchema x)
(let [[p+s1 s2] (:preds-and-schemas (s/if map?
{:first :schema} {:second :schema})
)]
{:s1 (second p+s1) :s2 s2})
x
)
@nha to walk multiple paths the general answer is to use multi-path
, e.g. (multi-path :left :right)
@nha btw instead of (fn [v] true)
for default case you can just write STAY