Skip to content

Instantly share code, notes, and snippets.

@vhutov
Last active June 23, 2020 22:26
Show Gist options
  • Save vhutov/9114bf813a39b8e2b837319a5f0efa78 to your computer and use it in GitHub Desktop.
Save vhutov/9114bf813a39b8e2b837319a5f0efa78 to your computer and use it in GitHub Desktop.
Third type
import io.circe.{Encoder, Decoder}
import cats.effect.Concurrent
import cats.syntax.either._
case class JmsMessage[T](value: T, metadata: Metadata)
class JmsParentController[
F[_] : Concurrent,
Request : Encoder,
SuccessResponse : Decoder,
FailureResponse : Decoder
](...) extends ParentController[...] {
private type Message = Either[SuccessResponse, Either[FailureResponse, QuotaRequest]]
def processResponse(message: JmsMessage[Message]): F[Unit] = {
message.value match {
case Left(msg) ⇒ processSuccess(msg)
case Right(Left(msg)) ⇒ processFailure(msg)
case Right(Right(msg)) ⇒ processQuota(msg)
}
}
private def processSuccess(succ: JmsMessage[SuccessMessage]): F[Unit] = F.unit
private def processFailure(succ: JmsMessage[FailureMessage]): F[Unit] = F.unit
private def processQuota(succ: JmsMessage[QuotaRequest]): F[Unit] = F.unit
private val decoder: Decoder[Message] =
// skipped required explicit type arguments to the Left and Right
// these won't compile
(Decoder[SuccessResponse].map(m ⇒ Left(m)) or
Decoder[FailureResponse].map(m ⇒ Right(Left(m)) or
Decoder[QuotaRequest].map(m ⇒ Right(Right(m))
)
private val F = Concurrent[F]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment