I am implementing ML Kit OCR feature and sometimes, the first several values are wrong and only after some time the camera stabilizes and produces correct values. I do not want to drop first X values because I do not know how many elements the flow would contain. So the best way would be to use some condition, which compares the current element with the previous one, but not sure.
Is there a function in Kotlin Flow API which will compare collected values and will collect only the one which occurred at least N times?
private val _detectedValues = ConflatedBroadcastChannel<String>()
val detectedFlow = _detectedValues
.asFlow()
.map { it.replace(" ", "") }
.filter { it.checkRegex() }
.onEach {
Log.i(TAG, "detected: $it")
}