Last active
          August 29, 2015 13:55 
        
      - 
      
- 
        Save mkremins/8760717 to your computer and use it in GitHub Desktop. 
    Clojure utility fns for working with zippers
  
        
  
    
      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
    
  
  
    
  | (require '[clojure.zip :as z]) | |
| (defn forms-zip | |
| "Returns a clojure.zip zipper over a tree of Clojure forms." | |
| [form] | |
| (z/zipper coll? | |
| #(if (map? %) (interleave (keys %) (vals %)) (seq %)) | |
| #(cond | |
| (map? %1) (apply hash-map %2) | |
| (seq? %1) %2 | |
| (vector? %1) (vec %2)) | |
| form)) | |
| (defn zip-seq | |
| "Returns a depth-first lazy sequence of locations in zipper `zip`." | |
| [zip] | |
| (when-not (z/end? zip) | |
| (cons zip (lazy-seq (zip-seq (z/next zip)))))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment