All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.kizitonwose.calendar.data.DataStore.kt Maven / Gradle / Ivy

Go to download

A highly customizable calendar library for Compose Multiplatform, backed by LazyRow/LazyColumn.

There is a newer version: 2.6.0-beta01
Show newest version
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