Re: Grouping and nested keys in a hash

2014-01-16 Thread James Conroy-Finn
Thank you for sharing. I think the final `s` needs to be `data`, right? On 16 Jan 2014, at 14:53, Jan Herich wrote: > Here we go, more generic solution: > > (defn transform [data delimiter] > (reduce (fn [acc [k v]] > (let [key-strs (-> k (name) (str/split delimiter))] > (assoc-in

Re: Grouping and nested keys in a hash

2014-01-16 Thread James Conroy-Finn
"B"}) > > (group-by #(-> % first str second str keyword) v) > > =>{:b [[:b--name "B"] [:b--id 2]], :a [[:a--id 1] [:a--name "A"]]} > > (reduce-kv #(assoc % %2 (into {} %3)) {} *1) > > => {:a {:a--id 1, :a--name "A"}, :b {:b-

Grouping and nested keys in a hash

2014-01-16 Thread James Conroy-Finn
Hello all, I've found myself stuck trying to move matching keys in a hash into a nested hash. For example,: {:a--id 1 :a--name "A" :b--id 2 :b--name "B"} ;=> {:a {:id 1 :name "A"} :b {:id 2 :name "B"}} I've tried `clojure.walk`, I've tried building the args to `assoc-in`, and using `apply`.