On Mon, Jan 5, 2009 at 9:53 AM, Christophe Grand <christo...@cgrand.net> wrote:
>
> Chouser a écrit :
>> On Dec 12 2008, 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))))
>>>
>>
>> This isn't in clojure.core yet (any reason why not?) so would you mind
>> if I add it to clojure.contrib.seq-utils?  Or of course you can do it
>> if you prefer.  :-)
>>
>
> What do you think of adding rec-cons, rec-cat and your (fixed) cute
> version instead to seq-utils?
> (see http://clj-me.blogspot.com/2009/01/recursive-seqs.html for rec-cat
> and rec-cons)

That'd be fine too, especially for rec-cons and rec-cat.  The
'reduction' in your blog makes a nice example, but I assume it runs
slower than your version above.

--Chouser

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