Last active
June 23, 2020 22:26
-
-
Save vhutov/9114bf813a39b8e2b837319a5f0efa78 to your computer and use it in GitHub Desktop.
Third type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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