I have the following code:
override def getStandsByUser(email: String): Try[Seq[Stand]] =
(for {
user <- OptionT(userService.findOneByEmail(email)): Try[Option[User]]
stands <- OptionT.liftF(standService.list()):[Try[List[Stand]]]
filtered = stands.filter(stand => user.stands.contains(stand.id))
} yield filtered).getOrElse(Seq())
}
I want to add logging on each stage of the processing - so I need to introduce writer monad and stack it with monad transformer OptionT. Could you please suggest how to do that?
The best way to do this is to convert your service calls into using
cats-mtl
.For representing
Try
orOption
you can useMonadError
and for logging you can useFunctorTell
. Now I don't know what exactly you're doing inside youruserService
orstandService
, but I wrote some code to demonstrate what the result might look like:This way we can avoid all of the calls to
liftF
and easily compose our different services even if they will use different monad transformers at runtime.