I have the following code to listen to updates bei...
# coroutines
j
I have the following code to listen to updates being made to a list in a datastore object. With flow, i map it to get another list within that list and filter out what changes has been made and send back the updated object.
Copy code
fun getOptionFlow(configurationName: String): Flow<OptionInfo?> {
        var oldOptionlist = getOptionListBlocking(configurationName)
        return datastore.data.catch { exception ->
            if (exception is IOException) {
                emit(Settings.getDefaultInstance())
            } else {
                throw exception
            }
        }.map { settings ->
            val result = settings.configurationsList.first { it.name.equals(configurationName) }.optionList
            val difference = result.filter { !oldOptionlist.contains(it) }
            oldOptionlist = result
            difference.firstOrNull()
        }
}
Now this is pretty ugly, and I am ashamed of the monster I have created, is there a more flow like solution that does not need to result saving a local variable?