Created
June 10, 2015 13:38
-
-
Save geraldodev/dbb25936653be5162e90 to your computer and use it in GitHub Desktop.
unfinished missing update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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