![]() And obviously there is a function findLast () to return the last found element.įirst(), firstOrNull(), last(), lastOrNull() and component1–5() return exact elements from the collection. There is a really simple realization inside this function: public inline fun Iterable.forEachIndexed(action: (index: Int, T) -> Unit): Unit įind() returns you the first found element. ![]() The most common operation when you work with collections is iteration through collection items for (int i = 0 i friend.id = index Let’s check all important functions that we have in the llection framework and compare it to an implementation to Java. But if we compare it to Rx, there are no subscribers, observers, etc. So the idea is that you have some stream of data, and using some functions you can receive some required state of the stream. This approach is very similar to Java 8 collections and Rx usage. find (predicate) and firstOrNull (predicate) are identical in behaviour and find can be considered alias of firstOrNull find is kept around as an alias because its more intuitive and discoverable for programmers not already familiar with these Linq-style - or functional - methods. Now I am going to show you the coolest thing in Kotlin collections – the functional approach Kotlin provides on top of collections. Software Engineer Android the two previous articles we talked about collections structure and all the possible ways to create them.
0 Comments
Leave a Reply. |