malli

https://github.com/metosin/malli :malli:
ikitommi 2020-08-02T16:38:58.293200Z

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.

ikitommi 2020-08-02T16:39:21.293500Z

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

ikitommi 2020-08-02T16:40:35.294Z

(also, performant, as it’s only protocols and vector indexes)

borkdude 2020-08-02T19:18:09.294400Z

@ikitommi Published dynaload to Clojars: https://clojars.org/borkdude/dynaload