File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
tp7/src/main/kotlin/fmt/kotlin/fundamentals Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package fmt.kotlin.fundamentals
2+
3+ fun cellar (init : CellarDsl .() -> Unit ): Cellar {
4+ val dsl = CellarDsl ()
5+ dsl.init ()
6+ val cellar = Cellar (
7+ barrels = dsl.barrels,
8+ bottles = dsl.bottles
9+ )
10+ return cellar
11+ }
12+
13+ class CellarDsl {
14+ val barrels = mutableListOf<Barrel >()
15+ val bottles = mutableListOf<Bottle >()
16+
17+ fun barrel (init : BarrelDsl .() -> Unit ): Barrel {
18+ val dsl = BarrelDsl ()
19+ dsl.init ()
20+ val barrel = Barrel (
21+ capacity = dsl.capacity
22+ )
23+ barrels.add(barrel)
24+ return barrel
25+ }
26+
27+ fun bottle (init : BottleDsl .() -> Unit ): Bottle {
28+ val dsl = BottleDsl ()
29+ dsl.init ()
30+ val bottle = Bottle (
31+ name = dsl.name,
32+ year = dsl.year
33+ )
34+ bottles.add(bottle)
35+ return bottle
36+ }
37+ }
38+
39+ class BarrelDsl {
40+ var capacity: Int = 0
41+ }
42+
43+ class BottleDsl {
44+ var name: String = " "
45+ var year: Int = 0
46+ }
You can’t perform that action at this time.
0 commit comments