Last active
January 1, 2016 13:59
-
-
Save mullr/8155158 to your computer and use it in GitHub Desktop.
This file contains 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
(defprotocol KeyAddressable | |
(kv-seq [this])) | |
(extend-protocol KeyAddressable | |
cljs.core/PersistentVector | |
(kv-seq [v] (map-indexed (fn [n x] [n x]) v)) | |
cljs.core/PersistentArrayMap | |
(kv-seq [x] (seq x)) | |
cljs.core/PersistentHashMap | |
(kv-seq [x] (seq x)) | |
default | |
(kv-seq [x] [])) | |
(defn all-paths [coll] | |
(mapcat (fn [[key val]] | |
(let [ps (all-paths val)] | |
(if (empty? ps) | |
[[key]] | |
(map (partial cons key) ps)))) | |
(kv-seq coll))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment