9

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.

Lasf
  • 2,536
  • 1
  • 16
  • 35

1 Answers1

17

You can do that with .sequence from cats:

import doobie.implicits._
import cats.implicits._

...

val res = progList.sequence // ConnectionIO[List[Unit]]
Alvaro Carrasco
  • 6,103
  • 16
  • 24