Is it possible to `filterNotNull` a `MutableStateF...
# coroutines
j
Is it possible to
filterNotNull
a
MutableStateFlow
and keep returning a
StateFlow
instead of a
Flow
? It is forcing me to add an
stateIn
to retransform the
Flow
into
StateFlow
g
I thought states couldn't be nullable
j
They can be nullable but I think there is no way to filter the emission of null states without
stateIn
i
The whole point of
StateFlow
is that it has always has a
value
. If your upstream
MutableStateFlow
only emits
null
, then
filterNotNull
never emits anything. That's why you need to use
stateIn()
to either set an
initialValue
(so that your
StateFlow
actually has a
value
) or use the suspend
stateIn
that suspends until the first value is emitted
👍 2
👍🏼 1
j
Thank you Ian 🙂 The last words about
stateIn
is what I was imagining