Oh my. Accumulating both :in
and :path
in explain errors seems redundant. If we know Schema and either of schema-path (`:path`) or a value-path (`:in`), we can calculate the other. Simplifies both -explain
and the malli utils. Sweet.
and the code is dead simple:
(defn in->path [schema in]
(loop [i 0, s schema, acc []]
(or (and (>= i (count in)) acc)
(recur (inc i) (get s (in i)) (if-not (m/-key s) (conj acc (in i)) acc)))))
(defn path->in [schema path]
(loop [i 0, s schema, acc []]
(or (and (>= i (count path)) acc)
(let [[i k] (if-let [k (m/-key s)] [i k] [(inc i) (path i)])]
(recur i (get s k) (conj acc k))))))
(also, performant, as it’s only protocols and vector indexes)
@ikitommi Published dynaload to Clojars: https://clojars.org/borkdude/dynaload