William Reed
04/11/2022, 12:24 PMConnected
and Disconnected
as a StateFlow
. I am trying to add more states such as Connecting
or LookingForSavedDevice
at a higher level in my program so I would like to use a StateFlow
which both takes in emissions from the library functions as well as allow me to mutate the StateFlow
myself.
So I think I'm looking for a way to collect into another flow:
bluetoothLibrary.stateFlow.collect(myOtherStateFlow)
I'm aware I can just emit into the new flow in a collect { }
block or onEach { }
but I'm not sure what is canonicalephemient
04/11/2022, 1:12 PMmyOtherStateFlow.emitAll(bluetoothLibrary.stateFlow)
is equivalent to
bluetoothLibrary.stateFlow.collect { myOtherStateFlow.emit(it) }
but is that really what you want? in most cases I'd consider
val myFlow = merge(
bluetoothLibrary.stateFlow,
myOtherStateFlow,
)
to be better than having multiple mutators of a single MutableStateFlowWilliam Reed
04/11/2022, 1:15 PMmerge
. I'll have to check if that still returns a StateFlow
or just a Flow
at that point but otherwise that's a great idea. Thank you