Kurt Renzo Acosta
11/26/2020, 6:55 AMprivate val _myFlow = MutableStateFlow<String?>(null)
val myFlow: Flow<String> get() = _myFlow.filterNotNull()
But I want to expose the flow as a StateFlow to the consumer. I can use asStateFlow() but I can’t use filterNotNull() anymore as it converts it back to a FlowManuel Wrage
11/26/2020, 8:17 AMKurt Renzo Acosta
11/26/2020, 8:18 AMManuel Wrage
11/26/2020, 8:19 AMKurt Renzo Acosta
11/26/2020, 8:20 AMManuel Wrage
11/26/2020, 8:23 AMKurt Renzo Acosta
11/26/2020, 8:24 AMFlow as compared to using StateFlow or SharedFlow where values are just replayedManuel Wrage
11/26/2020, 8:26 AMKurt Renzo Acosta
11/26/2020, 8:28 AMStateFlow is a SharedFlow that only holds one valueManuel Wrage
11/26/2020, 8:30 AMSharedFlow you wouldn't need to provide an initial value but the flow would still be shared.Manuel Wrage
11/26/2020, 8:31 AMKurt Renzo Acosta
11/26/2020, 8:31 AMKurt Renzo Acosta
11/26/2020, 8:33 AMviewModel.flow
.onEach { ... }
.launchIn(...)
viewModel.flow
.combine(viewModel.flow2) { ... }
.onEach { ... }
.launchIn(...)
Again, if my understanding is correct, consuming both of those that way would run two instances of that Flow as compared with using StateFlow / SharedFlow which would just replay and share values so I saw it as a way to optimize things.Manuel Wrage
11/26/2020, 8:38 AM