Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 220.127.116.11 release ready!
Updated 28 February 2020
Kotlin Scope functions
The Kotlin standard library contains several functions that are used for executing a block of code within the context of an object. When you call such a function on an object with a lambda expression provided, it forms a temporary scope. Here, we will check five of them:-
Kotlin let is a scoping function wherein the variables declared inside the expression cannot be used outside. let takes the object it is invoked upon as the parameter and returns the result of the lambda expression.
the key ‘it’ keyword contains a copy of the property inside let.
Kotlin run is another interesting function. The following example demonstrates its use cases.
As the name says, also expressions do some additional processing on the object it was invoked.
Unlike let, it returns the original object instead of any new return data. Hence the return data has always the same type.
Like let, also uses it too.
Kotlin apply is an extension function on a type. It runs on the object reference (also known as the receiver) into the expression and returns the object reference on completion.
Like apply, this is used to change instance properties without the need to call dot operator over the reference every time.
You can get more information regarding the scope functions and their uses in the following link:-
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.