Re: Transforming a Seq 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 wrote: > user=>(def your-data [{:a 1 :b 2 :c 3} {:a 4

Re: Transforming a Seq 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 wrote: > On Wed, Nov 18, 2009 at 8:19 AM, Robert Campbell wrote: > > Hey guys, >

Re: Transforming a Seq to a Map

2009-11-18 Thread Meikel Brandmeyer
Hi, On Nov 18, 2:35 pm, Christophe Grand 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 are subscribed to th

Re: Transforming a Seq to a Map

2009-11-18 Thread Rich Hickey
On Wed, Nov 18, 2009 at 8:19 AM, Robert Campbell 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 {:a 7 :

Re: Transforming a Seq 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 wrote: > Hey guys, > > I'm having some trouble finding a nice way

Transforming a Seq 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,