Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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