Skip to content

Instantly share code, notes, and snippets.

@teyyihan
Last active April 25, 2021 01:28
Show Gist options
  • Save teyyihan/2c1bed6eb3203c7808a9e2e9f0a25a56 to your computer and use it in GitHub Desktop.
Save teyyihan/2c1bed6eb3203c7808a9e2e9f0a25a56 to your computer and use it in GitHub Desktop.
fun main() {
user {
name = "Teyyihan"
age = 22
tweet {
title = "Hi"
body = "body"
timestamp = 1231231L
}
}
}
inline fun user(crossinline block: User.() -> Unit = {}): User {
val user = User()
user.block()
return user
}
inline fun User.tweet(crossinline block: Tweet.() -> Unit = {}): Tweet {
val tweet = Tweet()
tweet.block()
this.tweet = tweet
return tweet
}
data class User(
var name: String = "",
var age: Int = 0,
var tweet: Tweet = Tweet()
)
data class Tweet(
var title: String = "",
var body: String = "",
var timestamp: Long = 0L
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment