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 29 February 2020
Lambdas are very useful with collections and in fact, they are the backbone of the advanced manipulation of collections.
The basic function to manipulate collection is filter. This function accepts as an argument a lambda and returns a new collection. The lambda is given as an argument an element of the collection and returns a Boolean. If the lambda returns TRUE for an element, that element is added to the new collection, otherwise, it is excluded.
In this example, the filter function returns all even numbers.
The function map creates a new collection created by applying the lambda supplied to map to each element of the collection.
The function find returns the first element of the collection that satisfies the condition set in the lambda. It is the same function as firstOrNull, which is a longer but also clearer name,
which is a longer but also clearer name.
The function groupBy allows dividing a collection into more groups according to the condition indicated.
The method fold collapses a collection to a unique value, using the provided lambda and a starting value.
In the previous example, the first time we start with 0 and added all elements until the end. In the second case, with start with 15 and subtracted alle elements. Basically, the provided value is used as an argument for the start in the first cycle, then the start becomes the value returned by the previous cycle.
So, in the first case the function behaves like this:
For more details, you can take alook on the following links:-
https://kotlinlang.org/docs/reference/collection-filtering.html
https://kotlinlang.org/docs/reference/collection-grouping.html
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.