Son
Son

Reputation: 967

why is there a type parameter IO in Request as in http4s Request[IO]?

There's a type parameter IO in Request as in http4s Request[IO].

Why is it necessary, what do we have as an effect here, when is this effect executed?

Upvotes: 1

Views: 222

Answers (1)

gatear
gatear

Reputation: 946

You should read more about the tagless final pattern in Scala.

Here is the Request class:

abstract case class Request[F[_]](..., ...) extends Message[F] { .. }

Request needs based on its definition a type parameter F[_]

Request has methods that further constraint F[_]. For example:

  def decode[A](f: A => F[Response[F]])(implicit F: Monad[F], decoder: EntityDecoder[F, A]): F[Response[F]] 

This implicit F function argument means we need a Monad defined for F[_] otherwise you can't decode the request.

Request is made generic so you can easily use different F[_].
Besides the cats effect one you could use the Monix task.

Upvotes: 4

Related Questions