Not exactly: my initial acc value is usually something like #{} or [] but 
I've got the idea.

On Sunday, December 9, 2012 9:29:25 PM UTC+3, Alan Malloy wrote:
>
> You seem to have written (reduce (fn [acc [a b]] ...) (partition 2 1 
> coll)).
>
> On Sunday, December 9, 2012 7:39:21 AM UTC-8, Alexander Semenov wrote:
>>
>> Hi, folks.
>>
>> I'm wondering if Clojure library has 'reduce' function version which is 
>> like (reduce f coll) - i.e. it applies function to coll elements without 
>> the initial value but at the same time allows to use external accumulator 
>> which is passed to f as well. Better look at the code:
>>
>> (defn reduce-with-acc
>>   "Applies f to first two coll elements and acc producing new acc value 
>> for
>>   subsequent f calls. Returns acc. On singleton or empty collection 
>> returns
>>   acc immediately."
>>   [f acc coll]
>>   (loop [a (first coll) acc acc s (next coll)]
>>     (if (seq s)
>>       (let [b (first s)]
>>         (recur b (f a b acc) (next s)))
>>       acc)))
>>
>> Regards,
>> Alexander.
>>
>

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