Complete the code to create a sequence from a list.
val numbers = listOf(1, 2, 3, 4, 5) val seq = numbers.[1]()
The asSequence() function converts a collection into a sequence, enabling lazy operations.
Complete the code to filter even numbers from the sequence.
val numbers = sequenceOf(1, 2, 3, 4, 5) val evens = numbers.[1] { it % 2 == 0 }
The filter function selects elements that satisfy the given condition, here even numbers.
Fix the error in the code to map numbers to their squares.
val numbers = sequenceOf(1, 2, 3) val squares = numbers.[1] { it * it }
The map function transforms each element, here squaring each number.
Fill both blanks to create a sequence of squares of even numbers.
val numbers = listOf(1, 2, 3, 4, 5) val result = numbers.asSequence().[1] { it % 2 == 0 }.[2] { it * it }.toList()
First, filter selects even numbers, then map squares them.
Fill all three blanks to create a sequence of uppercase strings longer than 3 characters.
val words = listOf("cat", "dog", "elephant", "fox") val result = words.asSequence().[1] { it.length > 3 }.[2] { it.[3]() }.toList()
First, filter selects words longer than 3 letters, then map converts them to uppercase.
