Created
July 30, 2018 17:39
-
-
Save JorgeCastilloPrz/a1918519eb096d1682bd94da296daa2f to your computer and use it in GitHub Desktop.
PolymorphicLocalDataSource.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 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