commonMain.com.kizitonwose.calendar.data.DataStore.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compose-multiplatform Show documentation
Show all versions of compose-multiplatform Show documentation
A highly customizable calendar library for Compose Multiplatform, backed by LazyRow/LazyColumn.
package com.kizitonwose.calendar.data
/**
* Basically [MutableMap.getOrPut] but allows us read the map
* in multiple places without calling `getOrPut` everywhere.
*/
internal class DataStore(
private val store: MutableMap = HashMap(),
private val create: (offset: Int) -> V,
) : MutableMap by store {
override fun get(key: Int): V {
val value = store[key]
return if (value == null) {
val data = create(key)
put(key, data)
data
} else {
value
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy