January 2018
Intermediate to advanced
434 pages
14h 1m
English
To create a lazy list, we need to convert the list into a sequence. A sequence represents lazily evaluated collections. Let's understand it with an example:
fun main(args: Array<String>) { val A= listOf(1,2,3,4) var B=A.filter { println("checking ${it}") it%2==0 }}
This is the output:
checking 1checking 2checking 3checking 4
In the preceding example, the filter function was evaluated only when the object was defined.
fun main(args: ...Read now
Unlock full access