AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Empty mutable list kotlin4/10/2023 in case you are not aware, this has been discussed before on other issues on this repository, you might want to check the history. ![]() SharedFlow is very powerful and flexible, I only ever use StateFlow if it fits very well the use case, and if I don't have a natural initial value, then it does not fit the use case. I myself usually prefer just using SharedFlow configured similarly to a StateFlow. Have you considered wrapping every value in a "Resource" sealed class? Then all your StateFlow lacking a proper initial value could be constructed with Resource.Empty instead of null, if you are so averse to null :). value access in a try catch of some kind. Basically we would never be sure anymore if accessing a StateFlow value would be safe, and we would need to wrap every. ![]() value access raise an exception can cause so much unexpected errors in user code. I understand your points and I can say I also missed the no-initial-value StateFlow.īut I also think that your suggestion of making. There are many cases where an object cannot really have a default "empty" implementation, and having to make the T in StateFlow type nullable in order to support lazy initialization of objects might also introduce some bad consequences to the code base.Ĭould we rather have a default MutableStateFlow() constructor, combined with throwing an exception if stateFlow.value is accessed without having any value? This maybe belongs to the fail-safe vs fail-fast topic, but I really wish we did not have to make the T type nullable. To migrate ConflatedBroadcastChannel usage to StateFlow, start by replacing usages of the ConflatedBroadcastChannel() constructor with MutableStateFlow(initialValue), using null as an initial value if you don’t have one. ![]() Can we have a way of initializing a MutableStateFlow without having to use an initial value for it?Ĭonceptually, state flow is similar to ConflatedBroadcastChannel and is designed to completely replace ConflatedBroadcastChannel in the future.
0 Comments
Read More
Leave a Reply. |