Skip to content

Commit 90f28a2

Browse files
committed
tp7 step 1 solution
1 parent 99f3546 commit 90f28a2

File tree

1 file changed

+13
-2
lines changed
  • tp7/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ import jdk.internal.org.jline.utils.Colors.s
55
data class Cellar(
66
val bottles: List<Bottle>
77
) {
8-
fun describeAll(): String = TODO()
8+
fun describeAll() = callOnEveryBottle(Bottle::describe)
99

10-
val years: String = TODO()
10+
val years
11+
get() = callOnEveryBottle {
12+
it.year.toString()
13+
}
14+
15+
private fun callOnEveryBottle(block: (Bottle) -> String): String {
16+
var res = ""
17+
for (bottle in bottles) {
18+
res = res + "\n" + block(bottle)
19+
}
20+
return res
21+
}
1122
}

0 commit comments

Comments
 (0)