Skip to content

Instantly share code, notes, and snippets.

@JorgeCastilloPrz
Created July 31, 2018 10:34
Show Gist options
  • Save JorgeCastilloPrz/be46d4a9460eaaf3245496d543bacc8b to your computer and use it in GitHub Desktop.
Save JorgeCastilloPrz/be46d4a9460eaaf3245496d543bacc8b to your computer and use it in GitHub Desktop.
PolymorphicTaskRepository.kt
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