I am trying to write tests for my tagless algebra that it use the MonadError.
Here is tagless algebra with the interpreter:
trait DbConnector[F[_]] {
def read(url: DbUrl, user: DbUser, pw: DbPw): F[DbParams]
}
object DbConnector {
def apply[F[_]](implicit dc: DbConnector[F]): dc.type = dc
def impl[F[_] : MonadError[*[_], Throwable]](env: Environment[F])
: DbConnector[F] =
new LiveDbConnector[F](env)
}
and the test class with MonadError instance of Either:
class DbConnectorSpec extends munit.FunSuite {
test("Environment variables are not set") {
val monadError = MonadError[IO[Either[DbError, DbParams]], DbError]
implicit val badEnv = DbConnector.impl(LiveBadEnvironment())
}
}
the code does not get compiled, because of the error message:
cats.effect.IO[Either[io.databaker.db.DbError,io.databaker.db.DbParams]] takes no type parameters, expected: 1
[error] val monadErr = MonadError[IO[Either[DbError, DbParams]], DbError]
The MonadError is new to me and that is the first time, I am trying to use it. I have read the concept of the MonadError on https://www.scalawithcats.com/dist/scala-with-cats.html.
How to make it run?