Using List Store
KStore provides you with some convenient extensions to manage stores that contain lists.
Create a list store
listStoreOf is the same as storeOf, but defaults to empty list instead of null
val listStore: KStore<List<Pet>> = listStoreOf(file = Path("path/to/file"))
Get values
val pets: List<Pet> = listStore.getOrEmpty()
val pet: Pet? = listStore.get(0)
or observe values
val pets: Flow<List<Pet>> = listStore.updatesOrEmpty
Add or remove elements
listStore.plus(pet)
listStore.minus(pet)
Map elements
listStore.map { pet -> pet.copy(age = pet.age + 1) }
listStore.mapIndexed { index, pet -> pet.copy(age = index) }
Last modified: 07 August 2026