Build a study-plan DSL with explicit output
Create a DSL supporting a plan title, named sections, and lesson entries. Return immutable model snapshots, and keep scheduling or persistence outside the construction phase.
Your target call site is:
// Target API to implement in this exercise.
val roadmap = studyPlan("Kotlin foundations") {
section("Basics") {
lesson("Variables", minutes = 20)
lesson("Functions", minutes = 25)
}
}
Implement the model types first, then the builders, receiver entry point, validation, and a DSL marker. Require nonblank titles, positive durations, at least one section, and at least one lesson per section. Decide whether duplicate lesson titles are allowed across different sections.
Acceptance checks
Verify the exact model created by the sample, total duration of 45 minutes, rejection of missing sections, and rejection of zero-duration lessons. Add a test proving later builder changes cannot mutate a prior result.
Extension: generate Markdown from the model in a separate pure function. This demonstrates why a DSL should construct data rather than mix configuration with file-writing side effects.