Created
June 13, 2019 13:22
-
-
Save kibotu/3b0492d29a0d8677dc657a13553cb5cc to your computer and use it in GitHub Desktop.
Generic Repository Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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