Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to transform each number by doubling it using the map operator.
Kotlin
val numbers = flowOf(1, 2, 3) val doubled = numbers.[1] { it * 2 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter instead of map will only select elements, not transform them.
Using collect is for consuming the flow, not transforming it.
✗ Incorrect
The map operator applies a transformation to each element in the flow.
2fill in blank
mediumComplete the code to keep only even numbers using the filter operator.
Kotlin
val numbers = flowOf(1, 2, 3, 4) val evens = numbers.[1] { it % 2 == 0 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using map will transform elements but not filter them.
Using collect is for consuming the flow, not filtering.
✗ Incorrect
The filter operator keeps only elements that satisfy the condition.
3fill in blank
hardFix the error in the code to emit both original and doubled values using transform.
Kotlin
val numbers = flowOf(1, 2) val result = numbers.[1] { emit(it); emit(it * 2) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using map only emits one value per input.
Using filter does not emit new values, only filters existing ones.
✗ Incorrect
The transform operator allows emitting multiple values per input.
4fill in blank
hardFill both blanks to create a flow of squares of odd numbers.
Kotlin
val numbers = flowOf(1, 2, 3, 4, 5) val squaresOfOdds = numbers.[1] { it % 2 != 0 }.[2] { it * it }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using map before filter will square all numbers before filtering.
Using transform instead of map for simple transformation is more complex.
✗ Incorrect
First, filter keeps odd numbers, then map squares them.
5fill in blank
hardFill all three blanks to emit strings for numbers greater than 2, doubled and converted to string.
Kotlin
val numbers = flowOf(1, 2, 3, 4) val result = numbers.[1] { it [2] 2 }.[3] { (it * 2).toString() }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will select wrong numbers.
Using transform instead of map for simple transformation is unnecessary.
✗ Incorrect
Filter numbers greater than 2, then map to double and convert to string.