July 2018
Intermediate to advanced
242 pages
8h 6m
English
Let's consider the following example:
val collection = listOf("a", "b", "c", "d", "e", "f", "g", "h")val transformedCollection = collection.map { println("Applying map function for $it") it}println(transformedCollection.take(2))
In the first line, we created a list of strings and assigned it to the collection variable. Next, we are applying the map() function to the list. Mapping operation allows us to transform each element of the collection and return a new value instead of the original one. In our case, we are using it just to observe that map() was invoked by printing the message to the console. Finally, we want to filter our collection to contain only the first two elements using the take() function and print the content ...
Read now
Unlock full access