When designing a DSL, is it possible to use a lamb...
# dsl
r
When designing a DSL, is it possible to use a lambda to collect list inputs? I have not been able to find a way to make it work. What I want:
Copy code
dependsOn {
  "foo"
  "bar"
  "baz"
}
and then I can "collect" the 3 as a list. What I ended up doing for now is:
Copy code
dependsOn {
  add("foo")
  add("bar")
  add("baz")
}
And the definition looks like:
Copy code
fun dependsOn(init: MutableList<String>.() -> Unit)
Is there a better way to do this, such that I don't need the
add(...)
?
w
You could overload the plus operator. The HTML dsl does this for the string content of a tag
1
Its a little closer
r
thank you, i'll take a look!
ah ok it will use
+
instead of
add()
then
w
Yeah
👍 1
gratitude thank you 1
m
here is a nice article that explores some ideas: https://github.com/zsmb13/VillageDSL
r
oh wow, thank you Matteo!
👍 1