Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created June 10, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/dbb25936653be5162e90 to your computer and use it in GitHub Desktop.
Save geraldodev/dbb25936653be5162e90 to your computer and use it in GitHub Desktop.
unfinished missing update
(defn vector-map-zipper [m]
(letfn [(map?-or-persistent-vector? [x]
(or (map? x)
(instance? clojure.lang.PersistentVector x)))]
(let [filter-map-or-pv (filter (comp map?-or-persistent-vector? #(nth % 1)))]
(zip/zipper
(fn [x] (or (map?-or-persistent-vector? x)
(and (instance? clojure.lang.MapEntry x)
(map?-or-persistent-vector? (nth x 1)))))
(fn [x] (cond (instance? clojure.lang.PersistentVector x)
(seq x)
(map? x)
(seq (into (list) filter-map-or-pv x))
(instance? clojure.lang.MapEntry x)
(when (map?-or-persistent-vector? (nth x 1))
(seq (nth x 1)))))
(fn [x children]
(println (str "called update x:" x " children: " children)))
m))))
(comment
(let [m {:nome "geraldo"
:cidade {:nome "teofilo otoni"}
:filhos [{:nome "maria"} {:nome "neto"}]}]
(loop [z (vector-map-zipper m)]
(if (zip/end? z)
(zip/root z)
(let [n (zip/node z)]
(prn n)
(recur (zip/next z)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment