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 longest, padding the smaller ones > with a default value. I came up with this:
No code but an idea, calling length on the collection might force them to be itterated entirely why not define something like a lazy seq that takes: 1) the sequence to extend 2) the default value 3) a number of other sets As long as any of the lists is not epty return either first or the default value, this saves iterating through all lists, and is lazy :) A quick not tested and proably horribl wrong example: (defn extend-list [main-list default & other-lists] (if (some #(not (empty? %)) other-lists) (if (cons (empty? main-list) default (first main-list)) (apply extend-list (next main-list) default (map next other-lists))))) (this is not tested and just an idea, sorry short in time! -- 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 first post. 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