Redeem Now
Read More
Read now

Android make Kotlin DSL (Part1)


A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. Some examples of using DSLs (SQL, RegExp, Gradle).

What need we know to start DSL?

1.Lambda expressions
2.Higher-Order Function
3.Lambdas With Receivers

1.Lamda expression :
Lambda expression is a short way to define a function. A function without a name is called the anonymous function. Lambdas Expressions are anonymous functions that we can pass them as arguments to methods or return.

Lambda Expressions look like below:

2.Higher-Order Function

A higher-order function is a function that can take other functions as parameters and returns other functions.

Now Let’s start by converting a data model class into DSL

Now let’s make the DSL higher-order function:

Finally, we have created our data model object in the DSL way.

It’s worked fine, but you need to use it to access the properties instead of accessing them directly. We can fix it with the help of lambdas with receivers.

We will come back soon with part 2 lambdas with receivers

I hope this blog is useful to you. Thanks for reading.

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again