Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide syntax for raising errors in context #147

Closed
vlovgr opened this issue Jun 7, 2018 · 0 comments
Closed

Provide syntax for raising errors in context #147

vlovgr opened this issue Jun 7, 2018 · 0 comments

Comments

@vlovgr
Copy link
Owner

vlovgr commented Jun 7, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant