Kotlin DSL for collections
This is a simple data structure House which contains a (nullable) list of Person :
data class Person(val name: String,
val militaryYear: Int? = null,
val firstPregnantYear: Int? = null)
data class House(val persons: List?)
Person maybe male or female. Male has militaryYear value , Female has firstPregnantYear value.
I want to write a DSL to build the House object , like this :
val house = house {
person("John") {
militaryYear = 2003
}...