Skip to content

Instantly share code, notes, and snippets.

@monadplus
Last active April 5, 2019 10:05
Show Gist options
  • Save monadplus/943025395f54d1968357ba3b7ce27210 to your computer and use it in GitHub Desktop.
Save monadplus/943025395f54d1968357ba3b7ce27210 to your computer and use it in GitHub Desktop.
ActorRef
package com.stuart.dispatcher
import akka.actor.ActorRef
import io.estatico.newtype.macros.newtype
package object model {
trait TC1[T, A] {
def apply(a: A): T
}
implicit class ActorRefSyntax(self: ActorRef) {
def toTyped[T <: TypedActorRef](implicit ev: TC1[T, ActorRef]): T = ev.apply(self)
}
implicit def unapplyTypedActorRef(a: TypedActorRef): ActorRef = a.ref
sealed trait TypedActorRef {val ref: ActorRef}
final case class ZoneStateActorRef(ref: ActorRef) extends TypedActorRef
final case class BusinessEventListenerRef(ref: ActorRef) extends TypedActorRef
final case class TravelCostActorRef(ref: ActorRef) extends TypedActorRef
final case class ComputationFlowActorRef(ref: ActorRef) extends TypedActorRef
final case class SolutionActorRef(ref: ActorRef) extends TypedActorRef
final case class DispatcherCommandsWriterRef(ref: ActorRef) extends TypedActorRef
object ZoneStateActorRef {
implicit val tc1: TC1[ZoneStateActorRef, ActorRef] = (a: ActorRef) => ZoneStateActorRef(a)
}
object BusinessEventListenerRef {
implicit val tc1: TC1[BusinessEventListenerRef, ActorRef] = (a: ActorRef) => BusinessEventListenerRef(a)
}
object TravelCostActorRef {
implicit val tc1: TC1[TravelCostActorRef, ActorRef] = (a: ActorRef) => TravelCostActorRef(a)
}
object ComputationFlowActorRef {
implicit val tc1: TC1[ComputationFlowActorRef, ActorRef] = (a: ActorRef) => ComputationFlowActorRef(a)
}
object SolutionActorRef {
implicit val tc1: TC1[SolutionActorRef, ActorRef] = (a: ActorRef) => SolutionActorRef(a)
}
object DispatcherCommandsWriterRef {
implicit val tc1: TC1[DispatcherCommandsWriterRef, ActorRef] = (a: ActorRef) => DispatcherCommandsWriterRef(a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment