Re: Transforming a SeqMap to a Map

2009-11-22 Thread Emeka
(apply has-map (apply concat (map (fn [b] [(apply hash-map (apply concat (butlast b))) (val (last b))]) (list {9 5 9 9 7 8} {3 4 5 6 7 0} {{3 4, 5 6} 0, {8 9, 9 5} 8} I just added some noise! On Wed, Nov 18, 2009 at 2:05 PM, Sean Devlin francoisdev...@gmail.comwrote: user=(def your-data

Transforming a SeqMap to a Map

2009-11-18 Thread Robert Campbell
Hey guys, I'm having some trouble finding a nice way to perform a map transformation I need. I need to transform this: [ {:a 1 :b 2 :c 3} {:a 4 :b 5 :c 6} {:a 7 :b 8 :c 9} ] into this: { {:a 1 :b 2} 3 {:a 4 :b 5} 6 {:a 7 :b 8} 9 } I wanted to use map, but each f in map only returns one value,

Re: Transforming a SeqMap to a Map

2009-11-18 Thread Christophe Grand
Hi (defn f [coll] (into {} (for [{c :c :as m} coll] [(dissoc m :c) c]))) or (defn f [coll] (reduce (fn [r {c :c :as m}] (assoc r (dissoc m :c) c)) {} coll)) hth, Christophe On Wed, Nov 18, 2009 at 2:19 PM, Robert Campbell rrc...@gmail.com wrote: Hey guys, I'm having some trouble

Re: Transforming a SeqMap to a Map

2009-11-18 Thread Rich Hickey
On Wed, Nov 18, 2009 at 8:19 AM, Robert Campbell rrc...@gmail.com wrote: Hey guys, I'm having some trouble finding a nice way to perform a map transformation I need. I need to transform this: [ {:a 1 :b 2 :c 3} {:a 4 :b 5 :c 6} {:a 7 :b 8 :c 9} ] into this: { {:a 1 :b 2} 3 {:a 4 :b 5} 6

Re: Transforming a SeqMap to a Map

2009-11-18 Thread Meikel Brandmeyer
Hi, On Nov 18, 2:35 pm, Christophe Grand christo...@cgrand.net wrote: (defn f [coll]   (into {} (for [{c :c :as m} coll] [(dissoc m :c) c]))) (defn f [coll] (into {} (for [{c :c :as (- (dissoc :c) m)} coll] [m c]))) Untested. Sincerely Meikel -- You received this message because you

Re: Transforming a SeqMap to a Map

2009-11-18 Thread Sean Devlin
user=(def your-data [{:a 1 :b 2 :c 3} {:a 4 :b 5 :c 6} {:a 7 :b 8 :c 9}]) user=(into {} (map (juxt #(dissoc % :c) :c) your-data)) {{:a 1, :b 2} 3, {:a 4, :b 5} 6, {:a 7, :b 8} 9} On Nov 18, 8:36 am, Rich Hickey richhic...@gmail.com wrote: On Wed, Nov 18, 2009 at 8:19 AM, Robert Campbell