iguissouma
06/01/2020, 12:48 PMval v = village {
house {
+Person("Emily", 31)
+Person("Hannah", 27)
+Person("Alex", 21)
+Person("Daniel", 17)
}
house {
+Person("Joe", 48)
}
house()
house {
-Person("Sarah", 40)
-Person("Tom", 26)
-Person("Holly", 52)
}
}
gildor
06/01/2020, 1:51 PMPerson
object types, I would rather create a function:
addPerson(“Emily”, 31)
removePerson(…)iguissouma
06/01/2020, 1:56 PMif(conditon){addPerson(...)}
or
addPerson(name:String, age:Int, predicate:()->Boolean)
or
addPerson(...).onlyIf{ condition }
iguissouma
06/01/2020, 2:00 PMEvan R.
06/01/2020, 2:03 PMif (condition) addPerson()
is probably the way to goMatteo Mirk
06/01/2020, 2:04 PMhouse { }
lambda you can write whatever code you like, so using an if
seems the simplest way to do it for me. This said, I’m not quite sure about your use case, since a Kotlin DSL is usually employed for building objects declaratively, where you have all your data explicit, so I don’t see a particular application of such a pattern hereiguissouma
06/01/2020, 2:12 PMiguissouma
06/01/2020, 2:14 PMiguissouma
06/01/2020, 2:32 PMgildor
06/01/2020, 2:34 PMonlyIf
is not scalable, soon you will need some onlyIfOrElse etczsmb
06/01/2020, 2:50 PMif
statement (or a for
loop, for example) inside a DSL if I needed one. I haven't seen a DSL solution for an easily readable conditional statement yet that would be better than that.iguissouma
06/01/2020, 3:00 PM