Fork me on GitHub
#malli
<
2020-02-11
>
ikitommi06:02:58

(mu/assoc-in nil [:a ::c :d] int?)
; [:map [:a [:map [:b [:map [:c [:map [:d int?]]]]]]]]

ikitommi06:02:27

great thing about clojure is the functions compose nicely. HOFs are mostly 1:1 counterparts from Clojure (just cleaned up):

(defn update-in
  "Like [[clojure.core/update-in]], but for LensSchemas."
  [schema ks f & args]
  (letfn [(up [s [k & ks] f args]
            (assoc s k (if ks (up (get s k) ks f args)
                              (apply f (get s k) args))))]
    (up schema ks f args)))

ikitommi06:02:16

(defn update
  "Like [[clojure.core/update]], but for LensSchemas."
  [schema key f & args]
  (let [schema (m/schema schema)]
    (m/-set schema key (apply f (m/-get schema key nil) args))))

ikitommi06:02:37

Internally, there are just -get and -set functions in a LensSchema protocol. Dead simple.