Doobie transact over a list of ConnectionIO programs

Clash Royale CLAN TAG#URR8PPPDoobie transact over a list of ConnectionIO programs
Let's say I have a list of Doobie programs (all with Unit type parameters, fwiw):
Unit
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.
List[ConnectionIO[Unit]]
ConnectionIO[List[Unit]]
@YuvalItzchakov Isn't that ticket about the reverse operation?
– Alvaro Carrasco
9 secs ago
1 Answer
1
You can do that with .sequence from cats:
.sequence
import doobie.implicits._
import cats.implicits
...
val res = progList.sequence // ConnectionIO[List[Unit]]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You want to traverse
List[ConnectionIO[Unit]]intoConnectionIO[List[Unit]]? If so, that won't work: github.com/tpolecat/doobie/issues/465– Yuval Itzchakov
2 hours ago