Last active
April 25, 2021 01:28
-
-
Save teyyihan/2c1bed6eb3203c7808a9e2e9f0a25a56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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