Skip to content

Commit

Permalink
tp7 step 2 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ctruchi committed Feb 13, 2025
1 parent 75e7548 commit 79c51fe
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tp7/src/main/kotlin/fmt/kotlin/fundamentals/CellarDsl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package fmt.kotlin.fundamentals

fun cellar(init: CellarDsl.() -> Unit): Cellar {
val dsl = CellarDsl()
dsl.init()
val cellar = Cellar(
barrels = dsl.barrels,
bottles = dsl.bottles
)
return cellar
}

class CellarDsl {
val barrels = mutableListOf<Barrel>()
val bottles = mutableListOf<Bottle>()

fun barrel(init: BarrelDsl.() -> Unit): Barrel {
val dsl = BarrelDsl()
dsl.init()
val barrel = Barrel(
capacity = dsl.capacity
)
barrels.add(barrel)
return barrel
}

fun bottle(init: BottleDsl.() -> Unit): Bottle {
val dsl = BottleDsl()
dsl.init()
val bottle = Bottle(
name = dsl.name,
year = dsl.year
)
bottles.add(bottle)
return bottle
}
}

class BarrelDsl {
var capacity: Int = 0
}

class BottleDsl {
var name: String = ""
var year: Int = 0
}

0 comments on commit 79c51fe

Please sign in to comment.