Fork me on GitHub
#specter
<
2017-09-22
>
nha11:09:50

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
    )

nathanmarz13:09:38

@nha to walk multiple paths the general answer is to use multi-path, e.g. (multi-path :left :right)

nha13:09:41

Will try, thanks simple_smile

nathanmarz13:09:01

@nha btw instead of (fn [v] true) for default case you can just write STAY