Re: Using map on multiple collections.

2009-12-29 Thread Nicolas Buduroi
Big thanks to everyone, the suggestions given are all very welcome, even if I didn't really needed a better version as my use of mappad is really simple for now. It was just curiosity on my part. The lazy version by Heinz could be quite useful in other situations, I've added it to my toolbox.

Re: Using map on multiple collections.

2009-12-28 Thread Heinz N. Gies
On Dec 27, 2009, at 22:33 , Meikel Brandmeyer wrote: Checking for nil here is independent on the contents of the lists. The `(map seq lists)` first turns everything in lists into a seq. If a collection is empty it will be turned into nil. This nil is independent of any contained nil of

Re: Using map on multiple collections.

2009-12-27 Thread Heinz N. Gies
On Dec 26, 2009, at 21:09 , Meikel Brandmeyer wrote: Here is a more idiomatic (and fully lazy) version using the fnil function proposed by Rich here: http://groups.google.com/group/clojure/msg/f251cfd9baab440a (defn extend-tupel [default lists] (lazy-seq (let [seqs (map seq

Re: Using map on multiple collections.

2009-12-27 Thread Meikel Brandmeyer
Hi, Am 27.12.2009 um 12:22 schrieb Heinz N. Gies: (defn extend-tupel [default lists] (lazy-seq (let [seqs (map seq lists)] (when (some identity seqs) (cons (map (fnil first [default]) seqs) ; Note previously missing brackets. (apply extend-tupel default

Re: Using map on multiple collections.

2009-12-26 Thread Heinz N. Gies
On Dec 26, 2009, at 2:37 , Nicolas Buduroi wrote: I'll have a look at this, it would certainly make this function more idiomatic to Clojurians. Thanks for the suggestion. I've another one I like even better, it get's a bit away from mapping over n list but it could achiev the same:

Re: Using map on multiple collections.

2009-12-26 Thread Daniel Werner
On Dec 23, 6:04 am, Nicolas Buduroi nbudu...@gmail.com wrote: Hi, today I needed to use the map function on multiple collections which didn't had all the same length. In this case, it returns a sequence of the size of smallest one. But the problem I was facing was required to map until the end

Re: Using map on multiple collections.

2009-12-26 Thread Meikel Brandmeyer
Hi, Am 26.12.2009 um 14:45 schrieb Heinz N. Gies: On Dec 26, 2009, at 2:37 , Nicolas Buduroi wrote: I'll have a look at this, it would certainly make this function more idiomatic to Clojurians. Thanks for the suggestion. I've another one I like even better, it get's a bit away

Re: Using map on multiple collections.

2009-12-25 Thread Heinz N. Gies
On Dec 23, 2009, at 6:04 , Nicolas Buduroi wrote: Hi, today I needed to use the map function on multiple collections which didn't had all the same length. In this case, it returns a sequence of the size of smallest one. But the problem I was facing was required to map until the end of the

Re: Using map on multiple collections.

2009-12-25 Thread Nicolas Buduroi
On Dec 25, 1:52 am, Tom Hicks hickstoh...@gmail.com wrote: A slight modification, which I think avoids counting each collection twice: (defn append-val [val colls]   (let [lengths (map count colls)         maxlen (apply max lengths)]     (map #(concat %1 (repeat (- maxlen %2) val)) colls

Re: Using map on multiple collections.

2009-12-25 Thread Nicolas Buduroi
On Dec 25, 9:08 am, Heinz N. Gies he...@licenser.net wrote: On Dec 23, 2009, at 6:04 , Nicolas Buduroi wrote: Hi, today I needed to use the map function on multiple collections which didn't had all the same length. In this case, it returns a sequence of the size of smallest one. But the

Re: Using map on multiple collections.

2009-12-24 Thread Tom Hicks
A slight modification, which I think avoids counting each collection twice: (defn append-val [val colls] (let [lengths (map count colls) maxlen (apply max lengths)] (map #(concat %1 (repeat (- maxlen %2) val)) colls lengths) ) ) On Dec 23, 10:30 am, kyle smith

Re: Using map on multiple collections.

2009-12-23 Thread kyle smith
It's a little shorter if you unconditionally concat repeat. (defn append-val [val colls] (let [maxlen (apply max (map count colls))] (map #(concat % (repeat (- maxlen (count %)) val)) colls))) user (apply map + (append-val 0 [1] [2 3] [4 5 6])) (7 8 6) -- You received this message

Re: Using map on multiple collections.

2009-12-23 Thread Nicolas Buduroi
On Dec 23, 12:30 pm, kyle smith the1physic...@gmail.com wrote: It's a little shorter if you unconditionally concat repeat. (defn append-val [val colls]   (let [maxlen (apply max (map count colls))]     (map #(concat % (repeat (- maxlen (count %)) val)) colls))) user (apply map +

Using map on multiple collections.

2009-12-22 Thread Nicolas Buduroi
Hi, today I needed to use the map function on multiple collections which didn't had all the same length. In this case, it returns a sequence of the size of smallest one. But the problem I was facing was required to map until the end of the longest, padding the smaller ones with a default value. I