Created
July 31, 2018 10:34
-
-
Save JorgeCastilloPrz/be46d4a9460eaaf3245496d543bacc8b to your computer and use it in GitHub Desktop.
PolymorphicTaskRepository.kt
This file contains hidden or 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
| class TaskRepository<F>( | |
| private val localDS: DataSource<F>, | |
| private val remoteDS: RemoteDataSource<F>, | |
| AE: ApplicativeError<F, Throwable>) : ApplicativeError<F, Throwable> by AE { | |
| fun allTasksByUser(user: User): Kind<F, List<Task>> = | |
| localDS.allTasksByUser(user).handleErrorWith { | |
| when (it) { | |
| is UserNotInLocalStorage -> remoteDS.allTasksByUser(user) | |
| else -> raiseError(UnknownError(it)) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment