Re: Newbie: Separating and grouping the elements in a bunch of vectors
And to get the enclosing vector: (reduce conj [] (apply map vector [[:a :b] [1 2] ['a 'b]])) 2009/2/16 David Nolen dnolen.li...@gmail.com I'm sure it can be done, but it's not clear to me if you have a vector of vectors how Stuart's solution would work: 1:15 user= (map vector vecs) ([[:a0 :a1 :a2]] [[:b0 :b1 :b2]]) (apply (partial map vector) [[1 2 3] ['a 'b 'c] [cat dog bird]]) works on a vector of vectors. The OP wanted a vector of vectors as a result where the subvector length is the same as the number of vectors originally passed in. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
Thanks a lot, everyone. Isn't (reduce conj [] (apply map vector [[:a :b] [1 2] ['a 'b]])) equivalent to (into [] (apply map vector [[:a :b] [1 2] ['a 'b]])) though? On Feb 16, 3:55 pm, Laurent PETIT laurent.pe...@gmail.com wrote: And to get the enclosing vector: (reduce conj [] (apply map vector [[:a :b] [1 2] ['a 'b]])) 2009/2/16 David Nolen dnolen.li...@gmail.com I'm sure it can be done, but it's not clear to me if you have a vector of vectors how Stuart's solution would work: 1:15 user= (map vector vecs) ([[:a0 :a1 :a2]] [[:b0 :b1 :b2]]) (apply (partial map vector) [[1 2 3] ['a 'b 'c] [cat dog bird]]) works on a vector of vectors. The OP wanted a vector of vectors as a result where the subvector length is the same as the number of vectors originally passed in. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
On Mon, Feb 16, 2009 at 7:54 PM, samppi rbysam...@gmail.com wrote: Thanks a lot, everyone. Isn't (reduce conj [] (apply map vector [[:a :b] [1 2] ['a 'b]])) equivalent to (into [] (apply map vector [[:a :b] [1 2] ['a 'b]])) though? Yes. --Chouser --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Newbie: Separating and grouping the elements in a bunch of vectors
What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]] I could write a loop, I guess, but is there a nice, idiomatic, functional way of doing this? I didn't spot a way in clojure.contrib.seq-utils either. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
(map (fn [ rest] (apply vector rest)) [1 2 3] ['a 'b 'c] [cat dog bird]) On Sun, Feb 15, 2009 at 7:16 PM, samppi rbysam...@gmail.com wrote: What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]] I could write a loop, I guess, but is there a nice, idiomatic, functional way of doing this? I didn't spot a way in clojure.contrib.seq-utils either. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
Actually something closer to your exact expression is this: (apply (partial map (fn [ rest] (apply vector rest))) [[1 2 3] ['a 'b 'c] [cat dog bird]]) On Sun, Feb 15, 2009 at 7:42 PM, David Nolen dnolen.li...@gmail.com wrote: (map (fn [ rest] (apply vector rest)) [1 2 3] ['a 'b 'c] [cat dog bird]) On Sun, Feb 15, 2009 at 7:16 PM, samppi rbysam...@gmail.com wrote: What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]] I could write a loop, I guess, but is there a nice, idiomatic, functional way of doing this? I didn't spot a way in clojure.contrib.seq-utils either. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
Thanks a lot. I didn't know that map could take multiple collections. On Feb 15, 5:47 pm, David Nolen dnolen.li...@gmail.com wrote: Actually something closer to your exact expression is this: (apply (partial map (fn [ rest] (apply vector rest))) [[1 2 3] ['a 'b 'c] [cat dog bird]]) On Sun, Feb 15, 2009 at 7:42 PM, David Nolen dnolen.li...@gmail.com wrote: (map (fn [ rest] (apply vector rest)) [1 2 3] ['a 'b 'c] [cat dog bird]) On Sun, Feb 15, 2009 at 7:16 PM, samppi rbysam...@gmail.com wrote: What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]] I could write a loop, I guess, but is there a nice, idiomatic, functional way of doing this? I didn't spot a way in clojure.contrib.seq-utils either. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
From the original question it looked like there was a vector of unknown length of vectors [[a0 a1 a2] [b0 b1 b2] ...] So my solution is something like: 1:12 user= (def vecs [[:a0 :a1 :a2] [:b0 :b1 :b2]]) #'user/vecs 1:13 user= (partition (count vecs) (interleave (flatten vecs))) ((:a0 :a1) (:a2 :b0) (:b1 :b2)) This doesn't return a sequence of vectors and just a sequence of sequences. I'm sure it can be done, but it's not clear to me if you have a vector of vectors how Stuart's solution would work: 1:15 user= (map vector vecs) ([[:a0 :a1 :a2]] [[:b0 :b1 :b2]]) On Sun, Feb 15, 2009 at 7:54 PM, David Nolen dnolen.li...@gmail.com wrote: Of course ;) Keep forgetting the obvious things. On Sun, Feb 15, 2009 at 9:36 PM, Stuart Halloway stuart.hallo...@gmail.com wrote: (map vector [1 2 3] ['a 'b 'c] [cat dog bird]) - ([1 a cat] [2 b dog] [3 c bird]) Actually something closer to your exact expression is this: (apply (partial map (fn [ rest] (apply vector rest))) [[1 2 3] ['a 'b 'c] [cat dog bird]]) On Sun, Feb 15, 2009 at 7:42 PM, David Nolen dnolen.li...@gmail.com wrote: (map (fn [ rest] (apply vector rest)) [1 2 3] ['a 'b 'c] [cat dog bird]) On Sun, Feb 15, 2009 at 7:16 PM, samppi rbysam...@gmail.com wrote: What would I do if I wanted this: [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]] I could write a loop, I guess, but is there a nice, idiomatic, functional way of doing this? I didn't spot a way in clojure.contrib.seq-utils either. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Separating and grouping the elements in a bunch of vectors
I'm sure it can be done, but it's not clear to me if you have a vector of vectors how Stuart's solution would work: 1:15 user= (map vector vecs) ([[:a0 :a1 :a2]] [[:b0 :b1 :b2]]) (apply (partial map vector) [[1 2 3] ['a 'b 'c] [cat dog bird]]) works on a vector of vectors. The OP wanted a vector of vectors as a result where the subvector length is the same as the number of vectors originally passed in. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---