ryoakg
4/15/2016 - 1:32 AM

treelize.clj

(defn treelize [[k & ks] xs]
  (if-not k
    xs
    (->> xs
         (group-by k)
         (map (fn [[k xs]]
                [k (treelize ks xs)]))
         (into {}))))


(def data
  (treelize [:a :b :c]
            [{:a 1 :b 1 :c 1}
             {:a 1 :b 1 :c 2}
             {:a 1 :b 1 :c 3}
             {:a 1 :b 2 :c 1}
             {:a 1 :b 2 :c 2}
             {:a 2 :b 1 :c 1}
             {:a 2 :b 1 :c 2}
             {:a 2 :b 5 :c 1}
             {:a 2 :b 5 :c 2}]))

(get-in data [2 1])
(get-in data [2 5 1])