vlovgr/ciris

Provide syntax for raising errors in context

Closed this issue · 0 comments

When working with a context F[_] with a MonadError[F, Throwable] instance (for example, IO from cats-effect), one often ends up writing code similar to the following, in order to raise ConfigErrors as a Throwable error in the context.

val config: F[Either[ConfigErrors, Config]] = ...

config.flatMap {
  case Right(config) => F.pure(config)
  case Left(errors)  => F.raiseError(errors.toException)
}

The idea is to provide syntax for this common code, so that we can instead write the following.

import ciris.syntax._

val config: F[Either[ConfigErrors, Config]] = ...

config.orRaiseError