Caio Costa
11/01/2020, 2:59 PMgildor
11/01/2020, 3:05 PMgildor
11/01/2020, 3:07 PMCaio Costa
11/01/2020, 3:08 PMgildor
11/01/2020, 3:08 PMgildor
11/01/2020, 3:09 PMCaio Costa
11/01/2020, 3:10 PMgildor
11/01/2020, 3:11 PMCaio Costa
11/01/2020, 3:31 PMprotoDataStore.updateData
context to me but i still would have to call
userPref.copy()
everytime i had to update a value. But since it needs a named parameter, right now, i would have to repeat this code everywhere i call it.
That's why i asked if there was a way to pass named parameters as arguments because that way, the code would look cleaner. In my mind it would look like something like this:
fun <T> updateValue(namedParameter: String, value: T) {
protoDataStore.updateData { userPref ->
userPref.copy(namedParameter = value)
}
}
Caio Costa
11/01/2020, 3:33 PMCaio Costa
11/01/2020, 4:06 PMprivate suspend fun returnUpdateDataContext(instruction: UserPreferences): UserPreferences =
protoDataStore.updateData {
instruction
}
And its call would be like this:
returnUpdateDataContext (
protoDataStore.data.first().copy(name = "unkn0wn")
)
Caio Costa
11/01/2020, 4:07 PM.copy()
blockgildor
11/02/2020, 1:10 AMcopy()
is really the only good option for this case, it’s type safe after all