Home > other >  How to do a LIMIT with GROUP BY in Kotlin?
How to do a LIMIT with GROUP BY in Kotlin?

Time:10-29

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

CodePudding user response:

Use mapValues with take

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