I'm trying to define a
val textField: Flow<String>
that depends on a
val textInputEvents: Channel<TextInputEvent>
and a
val clearTextFieldEvents: Channel<ClearTextInputEvent>
. I'm trying to initialize the textField flow by combining the textInputEvents and clearTextFieldEvents channels and decide the value of the text field based of those two event streams, only problem is that just
val textField: Flow<String> = textInputEvents
.consumeAsFlow()
.combine(clearTextFieldEvents.consumeAsFlow()) { textInputEvent, clearTextFieldEvent ->
// Which one of the two just emitted?
// return textInputEvent.text or ""
}
wouldn't do it, since I have to know which one of the channels emitted value is the most recent one, which isnt possible.
So my question kinda is: is there a combine operator that also tells you which flow emitted the most recent value?
EDIT: perhaps this is a usecase for the select expression (
https://kotlinlang.org/docs/reference/coroutines/select-expression.html) ?