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

ReduceByKey for Collections #9064

Closed
scabug opened this issue Dec 31, 2014 · 4 comments
Closed

ReduceByKey for Collections #9064

scabug opened this issue Dec 31, 2014 · 4 comments

Comments

@scabug
Copy link

scabug commented Dec 31, 2014

I think it would be nice to have a simple reduceByKey for some collections like this:

str.split("").map(l => (l, 1)).reduceByKey(_+_)

I know there is an easy implementation for reduceByKey as in
[http://stackoverflow.com/questions/15975384/scala-reducebykey-function-use-any-type-that-has-method]
but by adding such a function to collection, we can have a faster implementation for it.

@scabug
Copy link
Author

scabug commented Dec 31, 2014

Imported From: https://issues.scala-lang.org/browse/SI-9064?orig=1
Reporter: Muhammad-Ali A'rabi (angellandros)

@scabug
Copy link
Author

scabug commented Jan 11, 2015

Muhammad-Ali A'rabi (angellandros) said:
I am implementing a class for paired Traversable type, to add these functions to it.
Anyway, why I can't assign the bloody task to myself?

@scabug
Copy link
Author

scabug commented Jan 13, 2015

Muhammad-Ali A'rabi (angellandros) said:
I reimplemented the method, and it's damn fast. On a paired list with 20 entries and 6 different keys, it is 25% faster than Stack Overflow implementation (although, that only works with +), and 4.5x faster than bare-hand implementation of it using a bunch of scala maps and reduces:

pairedList.groupBy(_._1).map(l => (l._1, l._2.map(_._2).reduce(_+_)))

Take a look at this:
[http://ideone.com/dyrkYM]

@NthPortal
Copy link

fixed by the addition of groupMapReduce in 2.13

@SethTisue SethTisue added this to the 2.13.0 milestone Dec 3, 2020
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

3 participants