Last active
July 17, 2018 14:50
-
-
Save AregevDev/a848edce3d11a40852f5abbfdb45a700 to your computer and use it in GitHub Desktop.
A cheatsheet about the stdlib lambdas in Kotlin
This file contains hidden or 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(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