So my for comprehension technically compiles fine currently, but if you look carefully I have a few unsafe .get
calls on the options.
for {
maybeProduct: Option[Product] <- EitherT.liftF {
for {
a <- ADao.get(123).transact(xa) // ConnectionIO[Option[A]]
b <- BDao.get(a.get).transact(xa) // ConnectionIO[Option[B]]
product <- CDao.get(b.get.productId.get).transact(xa) // ConnectionIO[Option[Product]]
} yield product
}
transaction <- EitherT(
TransactionDao.insert(..., maybeProduct.map(_.id),...).transact(xa)
)
}
I need help refactoring it to remove the unsafe calls in the following lines in the for comprehension
a <- ADao.get(123).transact(xa) // ConnectionIO[Option[A]]
b <- BDao.get(a.get).transact(xa) // ConnectionIO[Option[B]]
product <- CDao.get(b.get.productId.get).transact(xa) // ConnectionIO[Option[Product]]
Specifically the call to a.get
and b.get.productId.get
None
?flatTraverse
andflatMapN
OptionT
so you can justflatMap
everything in thefor