Obtaining a group of elements

The values can also be retrieved in groups. For example, you can take a group of values at once:

val firstFive = sequence.take(5)
println(firstFive.joinToString())

This will print the first five values separated by comma:

Notice that take() is an intermediate operation, so it returns a Sequence<T> that will be actually calculated  at a later time—when a terminal operation in invoked. So, in our example, calling take(5) will not actually have the sequence yield the values, but calling joinToString() will.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.176.88