Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Custom DSLs


A domain-specific language, or DSL, is a language that is specialized for one particular area. For example, online issue trackers, such as Jira, often come with a "little language" for querying, designed to make it easier to perform advanced searches. In programming, we most often see DSLs in the form of an API that has been tailored to make usage of the API easier.

Since Kotlin provides many features around the use of functions-named parameters, default parameters, operator overloading, and infix functions, to name a few-it makes Kotlin a powerful tool for creating your own custom DSL.

In this section, we will create a custom DSL used for assertions. This kind of functionality is often used in testing or behavior-driven development. In fact, we will devote a whole chapter to testing later in this book using the advanced KotlinTest library.

Infix functions as keywords

A simple assertion would be that a value is equal to another value. We could do this by having some kind of equal...