Skip to content

Instantly share code, notes, and snippets.

@JorgeCastilloPrz
Created July 30, 2018 17:39
Show Gist options
  • Save JorgeCastilloPrz/a1918519eb096d1682bd94da296daa2f to your computer and use it in GitHub Desktop.
Save JorgeCastilloPrz/a1918519eb096d1682bd94da296daa2f to your computer and use it in GitHub Desktop.
PolymorphicLocalDataSource.kt
class LocalDataSource<F>(A: ApplicativeError<F, Throwable>) :
DataSource<F>, ApplicativeError<F, Throwable> by A {
private val localCache: Map<User, List<Task>> =
mapOf(User(UserId("user1")) to listOf(Task("LocalTask assigned to user1")))
override fun allTasksByUser(user: User): Kind<F, List<Task>> =
Option.fromNullable(localCache[user]).fold(
{ raiseError(UserNotInLocalStorage(user)) },
{ just(it) }
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment