I *frequently* see:

(nth (iterate foo bar) n)

And:

(->> (iterate foo bar)
   (drop n)
   first)

I've also coded this in `avi` after being surprised no such thing exists:

(defn n-times
  [thing n a-fn]
  (reduce
    (fn [thing n]
      (a-fn thing))
    thing
    (range n)))

(which is kind of a bad implementation, now that I think of it):

Would it be useful to file a ticket for a new arity for iterate?:

(defn iterate
  ...
  ([f x n]
   (if (zero? n)
     x
     (recur f (f x) (dec n))))

There's a little bit of weirdness - this returns a single value, while the
other arity returns a lazy sequence.  However, I think it's the correct
name (and the original arity might  have better been named "iterations" for
symmetry with "reduce" and "reductions").  But ah well.

Thoughts?

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to