Colton Idle
05/14/2024, 2:31 PMfirst()
. It just looks smelly. Should I just be collecting the flow, and once the first item comes back then update with dataStore.edit?
val current = dataStore.data.map { d -> d[count] ?: 0L }.first()
dataStore.edit { d -> d[count] = current + 1 }
Colton Idle
05/14/2024, 3:05 PMColton Idle
05/14/2024, 3:30 PMephemient
05/14/2024, 3:31 PMColton Idle
05/14/2024, 3:35 PMColton Idle
05/14/2024, 3:40 PMColton Idle
05/14/2024, 3:40 PMColton Idle
05/14/2024, 3:43 PMTolriq
05/14/2024, 5:54 PMColton Idle
05/15/2024, 2:29 PMTolriq
05/15/2024, 2:35 PMdataStore.edit { prefs -> prefs[COUNTER_KEY] = prefs[COUNTER_KEY] :? 0 + 1 } `
You need to do the read and the calculation in the transformer.Colton Idle
05/15/2024, 2:42 PMdataStore.edit { prefs -> prefs[COUNTER_KEY] = (prefs[COUNTER_KEY] ?: 0) + 1 }
is what I have (elvis operator is wrong in the docs, and I believe it requires parens or else the ?: 0 + 1 will always set the value to 1 or the previous value.Colton Idle
05/15/2024, 2:42 PMTolriq
05/15/2024, 2:45 PMColton Idle
05/15/2024, 2:49 PM