Skip to content

Commit

Permalink
tp8 step 2 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ctruchi committed Feb 14, 2025
1 parent 327506f commit 6020c7f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tp8/src/main/kotlin/fmt/kotlin/fundamentals/Cellar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ data class Vineyard(
val cellars: List<Cellar>
) {

fun countBottles() = emptyMap<String, Int>()
fun countBottles() = cellars.fold(emptyMap<String, Int>()) { res, cellar ->
res.merge(cellar.bottles.groupingBy { it.name }.eachCount()) { n, m -> n + m }
}
}

data class Cellar(
Expand Down

0 comments on commit 6020c7f

Please sign in to comment.