Hi all, I’ve created a small DSL, but my challenge...
# getting-started
b
Hi all, I’ve created a small DSL, but my challenge is that I need a reference to some of the items in the tree I’m building, and I was wondering if you have any suggestions on how to do this. This is my current DSL:
Copy code
lateinit var childFolder1 : FolderNode
         lateinit var childFolder2 : FolderNode

         val rootFolder = buildFolders(am,"System") {
            childFolder1 = folder("A") {
                +entry(Attribute("x"), Sample("1"))
            }
            childFolder2 = folder("A") {
                +entry(Attribute("x"), Sample("2"))
                +entry(Attribute("x"), Sample("2"))
            }

            +childFolder1
            +childFolder2
        }

        println(childFolder1) // simplified here
As you can see, I need a reference to childFolder1 in my code, but my current solution seems a bit non-idiomatic, so I was wondering if you have any suggestions on how to improve this? (I’m also not sure if this is the right channel, the new setup confuses me a bit, so if I need to post this somewhere else, please let me know) Posted in #codereview