Created
June 15, 2013 22:15
-
-
Save djui/5789778 to your computer and use it in GitHub Desktop.
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
| (ns io.djui.misc) | |
| ;; Use case example for tree-seq | |
| (defn- map-traverse | |
| "Traverse a map with vectors in values as branches and return a list of key | |
| x's values. Example: | |
| {:a nil :x {:foo 1} :b [{:c nil :x 42} \"test\"]} => [{:foo 1} 42]" | |
| [map-tree x] | |
| (let [map-vals #(when (map? %) (vals %)) | |
| branch? (comp (partial some sequential?) map-vals) | |
| children (comp flatten (partial filter sequential?) vals) | |
| nodes (tree-seq branch? children map-tree)] | |
| (keep x nodes))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment