Group and sum with stdlib

Kotlin
data class Order(val customer: String, val cents: Int)

fun revenueByCustomer(orders: List<Order>): Map<String, Int> =
    orders.groupingBy { it.customer }
        .fold(0) { total, order -> total + order.cents }

fun main() {
    val orders = listOf(
        Order("alice", 1200),
        Order("bob", 800),
        Order("alice", 300),
    )
    println(revenueByCustomer(orders))
}