Skip to content

Instantly share code, notes, and snippets.

@JohanneA
Created November 22, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohanneA/82e41aba0174505749bcee4ba58df1de to your computer and use it in GitHub Desktop.
Save JohanneA/82e41aba0174505749bcee4ba58df1de to your computer and use it in GitHub Desktop.
Kotlin test DSL
//Lambda without receiver
fun buildString (
builderAction: (StringBuilder) -> Unit
) : String {
val stringBuilder = StringBuilder()
builderAction(stringBuilder)
return stringBuilder.toString()
}
val string = buildString {
it.append("Hello, ") // Note the need for adding 'it' in front
it.append("World!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment