This page is no longer maintained — Please continue to the home page at www.scala-lang.org

aggregate methods for traversables, what is it good for?

2 replies
Daniel Hinojosa
Joined: 2011-03-26,
User offline. Last seen 42 years 45 weeks ago.
In the source for TraversableOnce.scala, aggregate is defined as:

def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop)

I am not sure this provides anything of value that foldLeft doesn't already provide, considering that combop isn't even used.

Am I seeing things straight? Are there other implementations in other Traversables that I need to look at?
ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: aggregate methods for traversables, what is it good for?
foldLeft is not parallelizable; you have to run through in order.

aggregate is parallelizable, though as you can see, the default implementation just uses foldLeft.  (The parallel collections override this behavior.)

  --Rex

On Thu, Aug 18, 2011 at 2:25 PM, Daniel Hinojosa <dh.evolutionnext@gmail.com> wrote:
In the source for TraversableOnce.scala, aggregate is defined as:

def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop)

I am not sure this provides anything of value that foldLeft doesn't already provide, considering that combop isn't even used.

Am I seeing things straight? Are there other implementations in other Traversables that I need to look at?

Daniel Hinojosa
Joined: 2011-03-26,
User offline. Last seen 42 years 45 weeks ago.
Re: aggregate methods for traversables, what is it good for?
Excellent that's where I need to look.  Thanks Rex.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland