Simulating a microservice oriented Jurassic Park Service!
The attractions have been implemented as individual services which we provide the clients for.
- Use library cats to learn some simple functionality for writing lovely scala
- in particular:
asLeft
,asRight
,some
,none
,leftMap
andas
- practice for comprehension if desired
- try scala 2.13
pipe
andtap
perhaps? - extension exercises for Monad Transformers and State Monad
-
Create a service that accepts a
visitorId: String
and calls to 3 attractions:TRexClient.visit: Unit
, but must throw an exception when visitor diesTriceratopsClient.visit: Option[Error]
VelociraptorsClient.visit: Either[Error, Souvenir]
-
Error is one of
Injured
,LostLimb
orDead(cause: String)
-
Make up your own souvenirs!
-
After a successful visit to the T-Rex our jurassic service provides the visitor with a T-Shirt (which is a Souvenir)
-
When visitor has an accident (Error) no more attractions should be visited
-
Our service defines
visitAttractions(visitorId: String): Either[Error, List[Souvenir]]
- You can use Random.nextInt(n) to simulate getting a random service response
import cats._, cats.implicits._
- Add an AuditService that is called to log at each client on a successful visit
- A specific log when the visitor dies
- A specific log when the visitor has an accident but has not died
- AuditService returns IO[Unit] - try with and without Monad Transformers
- Use State monad for Random and Audit logs, so that is pure and testable (can you write tests currently?)