Best way to score and sum in Scala?

Posted by adam77 on Stack Overflow See other posts from Stack Overflow or by adam77
Published on 2010-05-21T04:24:48Z Indexed on 2010/05/21 4:30 UTC
Read the original article Hit count: 136

Filed under:
|

Is there a better way of doing this:

val totalScore = set.foldLeft(0)( _ + score(_) )

or this:

val totalScore = set.map(score(_)).sum

I think it's quite a common operation so was expecting something sleeker like:

val totalScore = set.sum( score(_) )

© Stack Overflow or respective owner

Related posts about scala

Related posts about sum