Your task today is to implement a toggle mechanism using Kotlin Flow. How should it work? Each time the flow source emits “something” – in this case, Unit – you should emit the negated previous value.
For the input: false, flowOf(Unit, Unit) you should create a flow: flowOf(false, true, false)
hint
Hint Do you know the scan operator?
In this snippet, the entire flow package has already been imported: import kotlinx.coroutines.flow.*
- Fill in the code.
- You can copy the code into IntelliJ/Android Studio, but it shouldn’t be necessary.
- Click “run” – the green triangle. The code will compile and several tests will be run.
- In the logs, you will see “try again” if the solution is incorrect, or “success” and a special code.
- Provide this code in the form below along with your email and click “send”.
- Solutions will be presented the next day on Instagram