I did something similar using (iterate rest coll), which I called iter-
rest:

(defn iter-rest
   "Takes the first (count coll) items from call to (iterate rest
coll).
   If passed function as first argument, calls it on each invocation
of
   rest, i.e. (iterate #(func (rest %)) coll)."
   ([coll] (take (count coll) (iterate rest coll)))
   ([func coll] (take (count coll) (iterate #(func (rest %)) coll))))

user=> (iter-rest (range 3))
((0 1 2) (1 2) (2))

I now realize a key difference is that, by using (count coll), iter-
rest fully realizes anything lazy; for Andrew's lazy version above, I
second the name "rests."

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

Reply via email to