cake-pattern

Akka and cake pattern

孤人 提交于 2019-12-04 10:26:38
问题 I'm confused how to ensure that my Actors have the appropriate dependencies using the cake pattern. I'm still getting to grips with this, and I can't find any examples anywhere. I'm basically just looking for a tutorial/resource to follow. Cheers, Chris. 回答1: Actors as dependency: trait DBComponent { def db: ActorRef // no compile time guarantees type K type V object DBActor { case class Put(key: K, value: V) case class Get(key: K) } class DBActor { import DBActor._ val db = scala.collection

Scala Cake Pattern and Dependency Collisions

纵然是瞬间 提交于 2019-12-04 01:47:54
I'm trying to implement dependency injection in Scala with the Cake Pattern, but am running into dependency collisions. Since I could not find a detailed example with such dependencies, here's my problem: Suppose we have the following trait (with 2 implementations): trait HttpClient { def get(url: String) } class DefaultHttpClient1 extends HttpClient { def get(url: String) = ??? } class DefaultHttpClient2 extends HttpClient { def get(url: String) = ??? } And the following two cake pattern modules (which in this example are both APIs that depend on our HttpClient for their functionality): trait

Can Scala's Cake Pattern be implemented in Haskell?

烈酒焚心 提交于 2019-12-03 06:53:44
问题 Using a number of newer language features in Scala it's possible to implement a composable component system and create components using the so called Cake Pattern, described by Martin Odersky in the paper Scalable Component Abstractions and also in a recent talk. Several of the Scala features used in the Cake Pattern have corresponding Haskell features. For example, Scala implicits correspond to Haskell type classes and Scala's abstract type members seem to correspond to Haskell's associated

Akka and cake pattern

我的梦境 提交于 2019-12-03 06:47:54
I'm confused how to ensure that my Actors have the appropriate dependencies using the cake pattern. I'm still getting to grips with this, and I can't find any examples anywhere. I'm basically just looking for a tutorial/resource to follow. Cheers, Chris. Actors as dependency: trait DBComponent { def db: ActorRef // no compile time guarantees type K type V object DBActor { case class Put(key: K, value: V) case class Get(key: K) } class DBActor { import DBActor._ val db = scala.collection.mutable.Map.empty[K, V] def receive = { case Put(k, v) => db.put(k, v) case Get(k) => sender ! db.get(k) } }

Scala cake-pattern compile error with Precog config pattern

僤鯓⒐⒋嵵緔 提交于 2019-12-01 21:04:47
问题 Following from this question, I have now the following: case class Pet(val name: String) trait ConfigComponent { type Config def config: Config } trait VetModule extends ConfigComponent { type Config <: VetModuleConfig def vet: Vet trait Vet { def vaccinate(pet: Pet) } trait VetModuleConfig { def extra: String } } trait VetModuleImpl extends VetModule { override def vet: Vet = VetImpl object VetImpl extends Vet { def vaccinate(pet: Pet) = println("Vaccinate:" + pet + " " + config.extra) } }

Scala cake-pattern compile error with Precog config pattern

谁都会走 提交于 2019-12-01 20:17:38
Following from this question, I have now the following: case class Pet(val name: String) trait ConfigComponent { type Config def config: Config } trait VetModule extends ConfigComponent { type Config <: VetModuleConfig def vet: Vet trait Vet { def vaccinate(pet: Pet) } trait VetModuleConfig { def extra: String } } trait VetModuleImpl extends VetModule { override def vet: Vet = VetImpl object VetImpl extends Vet { def vaccinate(pet: Pet) = println("Vaccinate:" + pet + " " + config.extra) } } trait AnotherModule extends ConfigComponent { type Config <: AnotherConfig def getLastName(): String

Cake pattern: one component per implementation, or one component per trait?

非 Y 不嫁゛ 提交于 2019-11-30 22:59:58
I'm currently working to use the cake pattern on my application. On exemples I have found across the web the exemples are kind of basic but doesn't involve more complex needs. What I'd like to do is not so fancy: I would like to have inside a cake pattern application, 2 services of the same type, using different implementations. trait UserServiceComponent { self: UserRepositoryComponent => val userService: UserService class DefaultUserService extends UserService { def getPublicProfile(id: String): Either[Error, User] = userRepository.getPublicProfile(id) } class AlternativeUserService extends

Cake pattern: one component per implementation, or one component per trait?

扶醉桌前 提交于 2019-11-30 17:23:49
问题 I'm currently working to use the cake pattern on my application. On exemples I have found across the web the exemples are kind of basic but doesn't involve more complex needs. What I'd like to do is not so fancy: I would like to have inside a cake pattern application, 2 services of the same type, using different implementations. trait UserServiceComponent { self: UserRepositoryComponent => val userService: UserService class DefaultUserService extends UserService { def getPublicProfile(id:

Why use scala's cake pattern rather than abstract fields?

天大地大妈咪最大 提交于 2019-11-28 22:51:46
I have been reading about doing Dependency Injection in scala via the cake pattern . I think I understand it but I must have missed something because I still can't see the point in it! Why is it preferable to declare dependencies via self types rather than just abstract fields? Given the example in Programming Scala TwitterClientComponent declares dependencies like this using the cake pattern: //other trait declarations elided for clarity ... trait TwitterClientComponent { self: TwitterClientUIComponent with TwitterLocalCacheComponent with TwitterServiceComponent => val client: TwitterClient

Why use scala's cake pattern rather than abstract fields?

只愿长相守 提交于 2019-11-27 14:28:21
问题 I have been reading about doing Dependency Injection in scala via the cake pattern. I think I understand it but I must have missed something because I still can't see the point in it! Why is it preferable to declare dependencies via self types rather than just abstract fields? Given the example in Programming Scala TwitterClientComponent declares dependencies like this using the cake pattern: //other trait declarations elided for clarity ... trait TwitterClientComponent { self: