Skip to content

Instantly share code, notes, and snippets.

@mullr
Last active January 1, 2016 13:59
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 mullr/8155158 to your computer and use it in GitHub Desktop.
Save mullr/8155158 to your computer and use it in GitHub Desktop.
(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