Let's say I have a list of Doobie programs (all with Unit
type parameters, fwiw):
val progList: List[ConnectionIO[Unit]] = prog1 :: prog2 :: ... :: Nil
Is there any way I can run them in one transaction? A for-comprehension won't work here, because I only know the precise composition of the program list at runtime. Essentially, I suppose I need to fold them together, I guess.
I suppose this question applies to Free Monads in Cats in general, so I'll tag Cats as well. Thanks.
You can do that with .sequence
from cats:
import doobie.implicits._
import cats.implicits._
...
val res = progList.sequence // ConnectionIO[List[Unit]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With