I often have the need to lazily iterate over rests of lists rather than 
elements. I frequently saw discussions about this topic. In CL it's called *
maplist*, in Haskell it's *tails* (Scala missing?). Of course there are 
several methods to do this, e.g. (take-while identity (iterate next S)), 
but if you use them recursivly, code reads badly. So my proposal would be 
to have a kind of following function in the core:

(defn maplist
  ([s] (maplist identity s))
  ([f s] (when-let [s (seq s)] (lazy-seq (cons (f s) (maplist f (next 
s)))))))
;(maplist [1 2 3]) -> ((1 2 3) (2 3) (3))

Questions:

   1. Would such a method help more developers?
   2. Is there a conceptional reason, to omit a maplist equivalent in 
   Clojure?

Thanks, Marc

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