Introduction to Type-Safe Builders: create a DSL in Kotlin
In this talk we discover what DSLs are and how we can manage to build them in Kotlin. Building a DSL in Kotlin is just about manipulating known Kotlin features such as lambdas, extension functions, infix functions ect.
a software system. You can't build a whole program with a DSL, but you often use multiple DSLs in a system mainly written in a general purpose language” “ Martin Fowler
---> Create function with lambda as parameter 3 ---> Use that function with lambda outside of parentheses 4 ---> Get rid of the "it" by changing the lambda block into a lambda with receiver 4' ---> We can one-line the expression using apply 5 ---> In order to use val and have proper data class, setup Builder Pattern for those data class 6 ---> Move Object creation functions in model class Builder 7 ---> List of Object ? Create a collection object in the builder change the function to be an "add" of item to the collection 8 ---> Want to change the collection style ? Create helper class. Subclass of list (of the object we want to create) 9 ---> Protect the DSL safety by scoping it with @DslMarker based annotation Raw steps to build our DSL