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 from mapping over n 
> list but it could achiev the same:
> 
> (defn extend-tupel [default & lists]
>   (if (some (complement empty?) lists)
>     (cons
>       (map (fn [l] (if (empty? l) default (first l))) lists)
>       (lazy-seq (apply extend-tupel default (map next lists))))
>     nil))
> 
> This takes a default value and N lists, then creates s tupels form this lists 
> untill all are empty, filling the ones that are empty before the rest with 
> the default value. You could use destruction in your map to make it look like 
> mapping over multiple lists. I like this better since each list will only 
> walked once, this is especially nicer in my eyes when it are lazy lists that 
> need to be evaluated each time the list is accessed.

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 lists)]
      (when (some identity seqs)
        (cons (map (fnil first default) seqs)
              (apply extend-tupel default (map rest seqs)))))))

Sincerely
Meikel

-- 
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

Reply via email to