Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(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))))
(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
You can’t perform that action at this time.