fbpx

#kotlinDevChallenge – 5

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.*

  1. Fill in the code.
  2. You can copy the code into IntelliJ/Android Studio, but it shouldn’t be necessary.
  3. Click “run” – the green triangle. The code will compile and several tests will be run.
  4. In the logs, you will see “try again” if the solution is incorrect, or “success” and a special code.
  5. Provide this code in the form below along with your email and click “send”.
  6. Solutions will be presented the next day on Instagram

more insights

Uncategorized
Jarosław Michalik

#kotlinDevChallenge 2023 summary

The KotlinDevChallenge was not just a competition, but a journey of learning, growth, and community engagement. Every participant in this challenge is a winner in

Read More »

AndroidPro newsletter 🚀

join 3057 developers reading AndroidPro newsletter every week

👉 tips & tricks, articles, videos

👉 every Thursday in your inbox

🎁 bonus on signup – Clean Architecture blueprint

brought to you by Jarek Michalik, Kotlin GDE

You can unsubscribe any time. For details visit our privacy policy.

android pro newsletter tips and tricks how to learn android