Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // I have no expirience with Scalaz, but I believe that Scalaz's Kleisli and the one of Cats are quite similar
  2. import cats.Id
  3. import cats.data.Kleisli
  4. import cats.implicits._
  5.  
  6. case class User(id: Int, name: String, active: Boolean)
  7.  
  8. trait UserService {
  9. type DeactivateConfigT
  10.  
  11. def deactivate(id: Int): Kleisli[Id, DeactivateConfigT, User]
  12. }
  13.  
  14. trait UserRepository {
  15. type GetConfigT
  16. type SaveConfigT
  17.  
  18. def get(id: Int): Kleisli[Option, GetConfigT, Unit]
  19. def save(user: User): Kleisli[Id, SaveConfigT, Unit]
  20. }
  21.  
  22. object DbUserRepository extends UserRepository {
  23. final case class DbConfig(host: String, user: String, password: String, db: String)
  24. type GetConfigT = DbConfig
  25. type SaveConfigT = DbConfig
  26.  
  27. // Implementation of the following methods are straightforward (or at least I think so), because
  28. // they do not depend on something returning Kleisli itself
  29. def get(id: Int): Kleisli[Option, GetConfigT, Unit] = ???
  30. def save(user: User): Kleisli[Id, SaveConfigT, Unit] = ???
  31. }
  32.  
  33. object DefaultUserService extends UserService {
  34. final case class DeactivateConfig(repo: UserRepository)
  35. type DeactivateConfigT = DeactivateConfig
  36.  
  37. // And here I have no idea how we should use UserRepository here. Especially taking into account
  38. // that we want to keep things decoupled and we depend here on the UserRepository trait, not a
  39. // concrete implementation with a known configuration requirements
  40. def deactivate(id: Int): Kleisli[Id, DeactivateConfigT, User] = ???
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement