How to do a LIMIT with GROUP BY in Kotlin?

Viewed 75

I have 400 players with 4 different skills I want to group them by skill but take only 20 from each skill

players.groupBy {
    it.skill
}

So the total is 80 i.e 20 from each

1 Answers

Use mapValues with take

players.groupBy {
    it.skill
}.mapValues{
    it.value.take(20)
}
Related