Mathias Brandt
06/29/2018, 10:47 AMPlayer
objects. Each Player
has a score: Int
. I want to calculate the total score for all players.
Can I do something like
list.reduce { ... }
directly, or do I have to use map as well, e.g.
list.map { it.score }.reduce { sum, score -> sum + score }
Lucas Ł
06/29/2018, 10:48 AMlist.sumBy{it.score}
?Mathias Brandt
06/29/2018, 10:48 AM