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 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Updated 28 September 2018
In this blog, we are going to see how kotlin lambda expression makes our code more expressive and concise. Recently, I’ve noticed that there are a few different ways to pass a function as a parameter. In this post I will use 2 functions: We have to declare the method, in such a way that it can receive the method as an argument. The most common and often more convenient (according to Kotlin documentation) is to pass a lambda expression.
In the above example, we have passed a lambda expression to calculateSum() method which will return the sum of these variables after execution of divide function. This is how we write lambda expression in a function: Expression_Name(Param1,Param2,Param3)->RetrunType
In this 2 example, we have lambda expression directly without passing method itself in the previous example we have passed the divide() function as the parameter. Regular functions receive only data parameters, whereas a function that receives another function as a parameter or returns a function, as a result, is called a Higher-order function. So, our functions that receive a lambda callback are basically higher-order functions.
Hope this blog will give you a basic idea of how we can pass lambda express or function to a method.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.