Complete the code to trigger execution of the sequence with a terminal operation.
val numbers = sequenceOf(1, 2, 3, 4) numbers.[1]()
The toList() function is a terminal operation that triggers the execution of the sequence and collects the results into a list.
Complete the code to print the first element of the sequence, triggering execution.
val seq = sequenceOf("a", "b", "c") println(seq.[1]())
The first() function is a terminal operation that triggers execution and returns the first element.
Fix the error in the code by choosing the correct terminal operation to trigger execution.
val seq = sequenceOf(10, 20, 30) val sum = seq.[1] { acc, i -> acc + i }
The reduce function is a terminal operation that aggregates the sequence elements and triggers execution.
Fill both blanks to collect even numbers from the sequence into a list, triggering execution.
val seq = sequenceOf(1, 2, 3, 4, 5) val evens = seq.[1] { it % 2 == 0 }.[2]()
filter selects even numbers (intermediate operation), and toList collects them into a list (terminal operation) triggering execution.
Fill all three blanks to transform, filter, and collect sequence elements, triggering execution.
val seq = sequenceOf("apple", "banana", "cherry") val result = seq.[1] { it.length }.[2] { it > 5 }.[3]()
map transforms strings to their lengths, filter selects lengths greater than 5, and toList collects results, triggering execution.