Does anybody know how you can create a `MutableSta...
# coroutines
t
Does anybody know how you can create a
MutableStateFlow
that allows duplicate events to be send. Basically mitigate the default
distinctUntilChanged
behavior?
b
Use SharedFlow instead, there is no way to do this with stateflow idiomatically (there is an ugly way though - via object wrapper, but even in this case some items may be lost if collector is slower than producer)
1
t
Can you give a simple sample of the
SharedFlow
that allows duplicate events?
b
Yep, something like
Copy code
MutableSharedFlow<Event>(1, extraBufferCapacity = 64)
👍 1
u
wait what? if I stateFlow.value = "5" twice, it will get emitted only once?
b
yes, because it represents "state" (obviously from its name) when you set it to "5" second time, state was not changed
☝️ 1
u
debatable, but okay
+ equals can be heavy ..a waste for collections, etc near UI especially, which will get diffed anyways