Creating a DSL

One of my big passions is cycling. The emotion of movement, the effort, the health benefits, and enjoying the landscape are some of the benefits (and I can keep going on and on).

I want to create a way to have a registry of my bikes and their components. For the prototype phase, I'll use XML, but later on we can change to a different implementation:

<bicycle description="Fast carbon commuter">    <bar material="ALUMINIUM" type="FLAT">    </bar>    <frame material="CARBON">        <wheel brake="DISK" material="ALUMINIUM">        </wheel>    </frame>    <fork material="CARBON">        <wheel brake="DISK" material="ALUMINIUM">        </wheel>    </fork></bicycle>  

This is the perfect scenario to create a type-safe builder in Kotlin.

In the end, my bicycle DSL should look ...

Get Functional Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.