June 2018
Intermediate to advanced
316 pages
6h 34m
English
Java 8 introduced lazy evaluation for collections using the Stream API. Kotlin has a similar feature called Sequence. The API of the Sequence class is similar to the API of the List class. But from the point of view of the return type, Sequence methods class can be classified into the following groups:
Intermediate methods return an instance of the Sequence class and terminal methods return an instance of the List class. The Sequence class actually starts to perform evaluations when meeting the terminal operator.
To create an instance of the Sequence class, you can just invoke the asSequence() method on a list or range:
(0..1_000_000) .asSequence()
This method looks as follows:
public fun <T> ...Read now
Unlock full access