Re: a data conversion question

2014-06-08 Thread Shahrdad Shadab
Yet another way: (reduce #(let [[k [v1 v2]] %2] (vec (concat % [[k v1]] [[k v2]]))) [] [[:a [1 2]] [:b [3 4]]]) On Jun 8, 2014, at 3:43 PM, boz wrote: > Thanks for the replies!! > > I goofed and only gave part of my loopy solution ... > here's the whole thing > > (defn do-one [id v]

Re: a data conversion question

2014-06-08 Thread boz
Wow! 'for' is a powerful thing!! This is perfect! On Sunday, June 8, 2014 12:32:44 PM UTC-7, François Rey wrote: > > (for [[k v] [[:a [1 2]] [:b [3 4]]] > n v] > [k n]) > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: a data conversion question

2014-06-08 Thread boz
Thanks for the replies!! I goofed and only gave part of my loopy solution ... here's the whole thing (defn do-one [id v] (loop [a (first v) r (rest v) result []] (if a (recur (first r) (rest r) (conj result [id a])) result))) (defn do-all [x] (loop [a (first x) b (rest x) re

Re: a data conversion question

2014-06-08 Thread François Rey
If you really want a vector, just wrap my answer with (into [] ...): (into[] (for[[k v] [[:a [1 2]] [:b [3 4]]] n v] [k n])) => [[:a 1] [:a 2] [:b 3] [:b 4]] -- You received this message because you are subscribed to the Google Groups "Clojure" group. To p

Re: a data conversion question

2014-06-08 Thread Lee Spector
On Jun 8, 2014, at 3:12 PM, boz wrote: > Is there a better way to take this... > > [[:a [1 2]] >[:b [3 4]]] > > and convert it to this... > > [[:a 1] >[:a 2] >[:b 3] >[:b 4]] > > than using a loop like this... > > (defn doit [id v] >

Re: a data conversion question

2014-06-08 Thread Alex Walker
(mapcat (fn [[k coll]] (map vector (repeat k) coll)) [[:a [1 2]] [:b [3 4]]]) => '([:a 1] [:a 2] [:b 3] [:b 4]) On Sunday, June 8, 2014 2:12:19 PM UTC-5, boz wrote: > > Is there a better way to take this... > > [[:a [1 2]] > [:b [3 4]]] > > and convert it to this... > > [[:a 1] >

Re: a data conversion question

2014-06-08 Thread François Rey
(for[[k v] [[:a [1 2]] [:b [3 4]]] n v] [k n]) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your