11package com.lukaslechner.coroutineusecasesonandroid.usecases.flow.usecase2
22
33import androidx.lifecycle.LiveData
4- import androidx.lifecycle.asLiveData
54import com.lukaslechner.coroutineusecasesonandroid.base.BaseViewModel
65import kotlinx.coroutines.CoroutineDispatcher
7- import kotlinx.coroutines.flow.*
8- import timber.log.Timber
96
107class FlowUseCase2ViewModel (
118 stockPriceDataSource : StockPriceDataSource ,
@@ -26,48 +23,5 @@ class FlowUseCase2ViewModel(
2623
2724 */
2825
29- val currentStockPriceAsLiveData: LiveData <UiState > = stockPriceDataSource
30- .latestStockList
31- .withIndex()
32- .onEach { indexedValue ->
33- Timber .d(" Processing emission ${indexedValue.index + 1 } " )
34- }
35- .map { indexedValue ->
36- indexedValue.value
37- }
38- .take(10 )
39- .filter { stockList ->
40- val googlePrice = stockList.find { stock ->
41- stock.name == " Alphabet (Google)"
42- }?.currentPrice ? : return @filter false
43-
44- googlePrice > 2300
45- }
46- .map { stockList ->
47- stockList.filter { stock ->
48- stock.country == " United States"
49- }
50- }
51- .map { stockList ->
52- stockList.filter { stock ->
53- stock.name != " Apple" && stock.name != " Microsoft"
54- }
55- }
56- .map { stockList ->
57- stockList.mapIndexed { index, stock ->
58- stock.copy(rank = index + 1 )
59- }
60- }
61- .map { stockList ->
62- stockList.filter { stock ->
63- stock.rank <= 10
64- }
65- }
66- .map { stockList ->
67- UiState .Success (stockList) as UiState
68- }
69- .onStart {
70- emit(UiState .Loading )
71- }
72- .asLiveData(defaultDispatcher)
26+ val currentStockPriceAsLiveData: LiveData <UiState > = TODO ()
7327}
0 commit comments