Created
November 22, 2021 15:01
-
-
Save JohanneA/507518abcc8ca1db13822e901c4990f3 to your computer and use it in GitHub Desktop.
Kotlin test DSL
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
// Lambda with receiver | |
fun buildString ( | |
builderAction: StringBuilder.() -> Unit // Note the location of the parentheses | |
) : String { | |
val stringBuilder = StringBuilder() | |
stringBuilder.builderAction() // This is now a method on the string builder | |
return stringBuilder.toString() | |
} | |
val string = buildString { | |
append("Hello, ") // Note we no longer need the qualifyer in front | |
append("World!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment