Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // I have no expirience with Scalaz, but I believe that Scalaz's Kleisli and the one of Cats are quite similar
- import cats.Id
- import cats.data.Kleisli
- import cats.implicits._
- case class User(id: Int, name: String, active: Boolean)
- trait UserService {
- type DeactivateConfigT
- def deactivate(id: Int): Kleisli[Id, DeactivateConfigT, User]
- }
- trait UserRepository {
- type GetConfigT
- type SaveConfigT
- def get(id: Int): Kleisli[Option, GetConfigT, Unit]
- def save(user: User): Kleisli[Id, SaveConfigT, Unit]
- }
- object DbUserRepository extends UserRepository {
- final case class DbConfig(host: String, user: String, password: String, db: String)
- type GetConfigT = DbConfig
- type SaveConfigT = DbConfig
- // Implementation of the following methods are straightforward (or at least I think so), because
- // they do not depend on something returning Kleisli itself
- def get(id: Int): Kleisli[Option, GetConfigT, Unit] = ???
- def save(user: User): Kleisli[Id, SaveConfigT, Unit] = ???
- }
- object DefaultUserService extends UserService {
- final case class DeactivateConfig(repo: UserRepository)
- type DeactivateConfigT = DeactivateConfig
- // And here I have no idea how we should use UserRepository here. Especially taking into account
- // that we want to keep things decoupled and we depend here on the UserRepository trait, not a
- // concrete implementation with a known configuration requirements
- def deactivate(id: Int): Kleisli[Id, DeactivateConfigT, User] = ???
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement