Skip to content

Instantly share code, notes, and snippets.

@agustarc
Created December 27, 2021 10:17
Show Gist options
  • Save agustarc/c6780edf39e7b0252edcd93908037142 to your computer and use it in GitHub Desktop.
Save agustarc/c6780edf39e7b0252edcd93908037142 to your computer and use it in GitHub Desktop.
public suspend fun DataStore<Preferences>.edit(
transform: suspend (MutablePreferences) -> Unit
): Preferences {
return this.updateData {
// It's safe to return MutablePreferences since we freeze it in
// PreferencesDataStore.updateData()
it.toMutablePreferences().apply { transform(this) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment