Created
December 31, 2009 01:29
-
-
Save bmabey/266552 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
(ns keys-in-test | |
(:use [clojure.test])) | |
(defn keys-in | |
"returns all possible keys in a nested map" | |
[m & ks] | |
(if (map? m) | |
(reduce into ks | |
(for [[k next-m] m] | |
(let [next-k (vec (conj (last ks) k))] | |
(keys-in next-m next-k)))) | |
ks)) | |
(deftest keys-in-test | |
(let [nested {"a" {"b" {"c1" 1 "c2" 2}}}] | |
(is (= (set [["a"] ["a" "b"] ["a" "b" "c1"] ["a" "b" "c2"]]) (set (keys-in nested)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment