Last active
February 9, 2019 07:52
-
-
Save renaudcerrato/094ca7414808fa54091c03f978704224 to your computer and use it in GitHub Desktop.
Lambda with Receiver
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 buildString(action: StringBuilder.() -> Unit) : String { | |
val sb = StringBuilder() | |
sb.action() | |
return sb.toString() | |
} | |
// inside the lambda, `this` refer to the StringBuilder | |
val s = buildString { | |
append("Hello!") | |
append("How are you?") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment