Client[F]
all the way down to some Repositories that do the HTTP requests, so when I'm creating the program, I have to instantiate them with F[_]
, which means the F
has to be Kleisli[F, Span[F], *]
, but the main body of my code executes within the BlazeClientBuilder
resource, so the Client[F]
's F[_]
has to have ConcurrentEffect
Client[F]
to Client[Kleisli...]
?
def wrapExistingClient[F[_], G[_]: Trace](underlyingClient: Client[F]): Client[G]
code laying around?
def liftKleisli[F[_]: Bracket[*[_], Throwable]: cats.Defer, A](
client: Client[F],
a: A
): Client[Kleisli[F, A, *]] = Client{
req: Request[Kleisli[F, A, *]] =>
val newReq = req.mapK(Kleisli.applyK(a))
client.run(newReq)
.mapK(Kleisli.liftK[F, A])
.map(_.mapK(Kleisli.liftK))
}
liftKleisli(blazeClient, baseSpan)
def liftKleisli[F[_]: Bracket[*[_], Throwable]: cats.Defer, A](client: Client[F]): Client[Kleisli[F, A, *]] =
Client{ req: Request[Kleisli[F, A, *]] =>
Resource.liftF(Kleisli.ask[F, A]).flatMap{ a =>
val newReq = req.mapK(Kleisli.applyK(a))
client.run(newReq)
.mapK(Kleisli.liftK[F, A])
.map(_.mapK(Kleisli.liftK))
}
}