Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods sumBy and productBy to TraversableOnce #4276

Closed
scabug opened this issue Feb 21, 2011 · 6 comments
Closed

Add methods sumBy and productBy to TraversableOnce #4276

scabug opened this issue Feb 21, 2011 · 6 comments

Comments

@scabug
Copy link

scabug commented Feb 21, 2011

Since there have methods minBy and maxBy in Traversable already, and in some cases it is useful if adding sumBy and productBy to TraversableOnce.

def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
  var sum = num.zero
  for(x <- this) sum = num.plus(sum, f(x))
  sum
}
@scabug
Copy link
Author

scabug commented Feb 21, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4276?orig=1
Reporter: Eastsun (eastsun)
Attachments:

  • fix-4276.diff (created on Apr 14, 2011 10:49:36 AM UTC, 3405 bytes)

@scabug
Copy link
Author

scabug commented Feb 21, 2011

@soc said:
I would like to support that.

Maybe it was just by chance, but I wondered how to do the same thing an hour ago. :-)

A practical use-case can be found in this question: [http://stackoverflow.com/questions/5064383]

@scabug
Copy link
Author

scabug commented Feb 22, 2011

@SethTisue said:
There's real value to minBy and maxBy; they replace messy code involving tuples. Here all you're avoiding is "map(...).sum" or "view.map(...).sum". It seems like API clutter to me.

@scabug
Copy link
Author

scabug commented Feb 22, 2011

@axel22 said:
We're leaving this as a future enhancement. Once enough suggestions about the collection API accumulate, and it becomes apparent which should be added, we will include as part of a new release.

@scabug
Copy link
Author

scabug commented Apr 14, 2011

@soc said:
Implementation with ScalaDoc

@SethTisue
Copy link
Member

SethTisue commented Feb 17, 2018

what I said in 2011. also, views work in strawman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants