Last active
April 18, 2021 20:22
-
-
Save Skyyo/1a22100995cf05a08973f0b5d3d5be14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private suspend fun observePriceUpdateFlow(index: Int, currencyPriceUpdateFlow: Flow<Int>) { | |
currencyPriceUpdateFlow.collect { newPrice -> | |
val newFluctuation = when { | |
newPrice > _currencyPrices.value[index].price -> PriceFluctuation.UP | |
else -> PriceFluctuation.DOWN | |
} | |
val updatedCurrencyPrice = _currencyPrices.value[index].copy( | |
price = newPrice, | |
priceFluctuation = newFluctuation | |
) | |
val mutableCurrencyPrices = _currencyPrices.value.toMutableList() | |
mutableCurrencyPrices[index] = updatedCurrencyPrice | |
_currencyPrices.value = mutableCurrencyPrices.toList() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment