Re: Small question: Best way to create a map with vector vals

2009-06-24 Thread Laurent PETIT
Oups, indeed this doesn't solve the problem, this other solution works (just a variant of Kresimir's one) : (reduce (fn [m [k v]] (update-in m [k] #(conj (or %1 []) %2) v)) {} [[:a 1] [:b 3] [:b 5] [:c 1]]) 2009/6/24 Laurent PETIT > Does this fit your need ? : > > (reduce (fn [m [k v]] (assoc m

Re: Small question: Best way to create a map with vector vals

2009-06-24 Thread Emeka
Have you tried zipmap? Emeka On Tue, Jun 23, 2009 at 10:09 PM, samppi wrote: > > The idiom (into {} coll-of-entries) is often used to create a map from > a collection of entries or two-sized vectors. But what if I want to do > something like this: > > (mystery-fn [[:a 1] [:b 3] [:b 5] [:c 1]])

Re: Small question: Best way to create a map with vector vals

2009-06-24 Thread Nicolas Oury
Hello, other solutions: (apply hash-map (apply concat [[:a 1] [:b 3] [:e 5] [:c 1]])) or (apply hash-map (mapcat identity [[:a 1] [:b 3] [:e 5] [:c 1]])) I didn't find any function equivalent to "apply concat". Is there something like a monadic join function for sequence in the API? Best reg

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread samppi
Thanks everyone. They all seem to take less time than the filter way too. On Jun 23, 4:05 pm, Cosmin Stejerean wrote: > On Tue, Jun 23, 2009 at 5:09 PM, samppi wrote: > > > The idiom (into {} coll-of-entries) is often used to create a map from > > a collection of entries or two-sized vectors. B

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread Cosmin Stejerean
On Tue, Jun 23, 2009 at 5:09 PM, samppi wrote: > > The idiom (into {} coll-of-entries) is often used to create a map from > a collection of entries or two-sized vectors. But what if I want to do > something like this: > > (mystery-fn [[:a 1] [:b 3] [:b 5] [:c 1]]) ; returns {:a [1], :b [3 > 5], :

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread Krešimir Šojat
Hi, Try: (def x [[:a 1] [:b 3] [:b 5] [:c 1]]) (into {} (map (fn [[k v]] [k [v]]) a)) Returns: {:c [1], :b [5], :a [1]} -- Krešimir Šojat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to t

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread joshua-choi
Come to think of it, this would also work for me: keeping the vector of pairs, and instead using filter to get the "values" of a key: (defn get-from-pairs [pairs key-to-fetch] (map #(get % 1) (filter #(= key-to-fetch (get % 0)) pairs))) (I wish the key and val functions were defined on vectors

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread Laurent PETIT
Does this fit your need ? : (reduce (fn [m [k v]] (assoc m k [v])) {} [[:a 1] [:b 3] [:b 5] [:c 1]]) HTH, -- Laurent 2009/6/24 samppi > > The idiom (into {} coll-of-entries) is often used to create a map from > a collection of entries or two-sized vectors. But what if I want to do > somethin

Re: Small question: Best way to create a map with vector vals

2009-06-23 Thread Krešimir Šojat
Sorry about that, didn't see that :b should concat it's vals: (def x [[:a 1] [:b 3] [:b 5] [:c 1]]) (reduce (fn [x [k v]] (assoc x k (if (contains? x k) (conj (x k) v) [v]))) {} x) Returns: {:c [1], :b [3 5], :a [1]} -- Krešimir Šojat --~--~-~--~~~---~--~~ You re

Small question: Best way to create a map with vector vals

2009-06-23 Thread samppi
The idiom (into {} coll-of-entries) is often used to create a map from a collection of entries or two-sized vectors. But what if I want to do something like this: (mystery-fn [[:a 1] [:b 3] [:b 5] [:c 1]]) ; returns {:a [1], :b [3 5], :c [1]}) The only way I can think of doing this is with a com