Exercise: Flow with history
As an exercise in my Kotlin Coroutines workshop, I ask participants to implement a withHistory
function that returns a flow of all the values that have been emitted. As a result, I often see the following implementation:
This implementation is not correct, as is illustrated by the usage example below. Your task is to fix it.
This problem can either be solved in the below playground or you can clone kotlin-exercises project and solve it locally. In the project, you can find code template for this exercise in effective/safe/FlowHistory.kt. You can find there starting code and unit tests.
Once you are done with the exercise, you can check your solution here.