On Dec 12, 3:35 pm, Christophe Grand <christo...@cgrand.net> wrote:
> I was sure it was a job for iterate:
>
> (defn reductions
> "Returns a lazy seq of the intermediate values of the reduction (as
> per reduce) of coll by f, starting with init."
> ([f coll]
> (if (seq coll)
> (for [s (iterate (fn [[x & s]] (if s
> (lazy-cons (f x (first s)) (rest s))))
> coll)
> :while s]
> (first s))
> (list (f))))
> ([f val coll]
> (reductions f (cons val coll))))
>
> It's interesting that the general case is [f coll] and not [f val coll].
>
Very clever.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---