Skip to content

Instantly share code, notes, and snippets.

@AregevDev
Last active July 17, 2018 14:50
Show Gist options
  • Select an option

  • Save AregevDev/a848edce3d11a40852f5abbfdb45a700 to your computer and use it in GitHub Desktop.

Select an option

Save AregevDev/a848edce3d11a40852f5abbfdb45a700 to your computer and use it in GitHub Desktop.
A cheatsheet about the stdlib lambdas in Kotlin
fun main(args: Array<String>) {
val str = "I am a string"
str.run {
// no lambda params, receiver is value type (String), returns R, the result of the lambda.
}
str.let {
// lambda params are value type (String), no receiver, returns R, the result of the lambda.
}
str.apply {
// no lambda params, receiver is value type (String), returns value type (String).
}
str.also {
// lambda params are value type (String), no receiver, returns value type (String).
}
with(str) {
// no lambda params, receiver is value type (String), returns R, the result of the lambda,
// it is NOT an extension function though the receiver will be defined as a parameter.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment