Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created June 13, 2019 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/3b0492d29a0d8677dc657a13553cb5cc to your computer and use it in GitHub Desktop.
Save kibotu/3b0492d29a0d8677dc657a13553cb5cc to your computer and use it in GitHub Desktop.
Generic Repository Interface
import androidx.lifecycle.LiveData
/**
* Generic interface for working with [T]
*/
interface Repository<T> {
/**
* Gets all [T].
*/
suspend fun all(): LiveData<List<T>>
/**
* Gets [T] by id.
*/
suspend fun getById(id: String): LiveData<T>
/**
* Deletes [T].
*/
suspend fun delete(item: T)
/**
* Deletes [T] by predicate.
*/
suspend fun delete(predicate: (T) -> Boolean)
/**
* Updates and inserts [T].
*/
suspend fun insertOrUpdate(item: T)
/**
* Updates and inserts list of [T].
*/
suspend fun insertOrUpdate(items: List<T>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment