I have a list of `Player` objects. Each `Player` h...
# announcements
m
I have a list of
Player
objects. Each
Player
has a
score: Int
. I want to calculate the total score for all players. Can I do something like
Copy code
list.reduce { ... }
directly, or do I have to use map as well, e.g.
Copy code
list.map { it.score }.reduce { sum, score -> sum + score }
l
how about
list.sumBy{it.score}
?
m
Ha! Wasn’t aware of that! Much nicer 😄