Skip to content

Commit 6020c7f

Browse files
committed
tp8 step 2 solution
1 parent 327506f commit 6020c7f

File tree

1 file changed

+3
-1
lines changed
  • tp8/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+3
-1
lines changed

tp8/src/main/kotlin/fmt/kotlin/fundamentals/Cellar.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ data class Vineyard(
44
val cellars: List<Cellar>
55
) {
66

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

1012
data class Cellar(

0 commit comments

Comments
 (0)