Type-safe builders
With the two previous sections (infix functions and operator overloading), we have a good foundation for building fantastic DSLs. A DSL is a language that is specialized to a particular domain, in contrast to general-purpose language (GPL). Classic examples of DSLs (even when people don't realize it) are HTML (markup) and SQL (relational database queries).
Kotlin provides many features to create internal DSLs (a DSL that runs internally inside a host GPL), but there is one feature that we still need to cover, type-safe builders. Type-safe builders let us define data in a (semi) declarative way and are very useful to define GUIs, HTML markup, XML, and others.
An example of a beautiful Kotlin DSL is TornadoFX. TornadoFX ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access