trait ErrorControl[F[_], G[_], E] extends Serializable
A type class for principled error handling.
ErrorControl
is designed to be a supplement to MonadError
with more precise typing.
It is defined as a relationship between an error-handling type F[A]
and a non-error-handling type G[A]
.
This means a value of F[A]
is able to produce either a value of A
or an error of type E
.
Unlike MonadError
's handleError
method, the controlError
function defined in this type class
will yield a value that free of any errors, since they've all been handled.
Must adhere to the laws defined in cats.laws.ErrorControlLaws.
- Alphabetic
- By Inheritance
- ErrorControl
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
accept[A](ga: G[A]): F[A]
Injects this error-free
G[A]
value into anF[A]
. -
abstract
def
controlError[A](fa: F[A])(f: (E) ⇒ G[A]): G[A]
Handle any error and recover from it, by mapping it to an error-free
G[A]
value.Handle any error and recover from it, by mapping it to an error-free
G[A]
value.Similar to
handleErrorWith
onApplicativeError
Example:
scala> import cats._, data._, implicits._ scala> EitherT(List(42.asRight, "Error!".asLeft, 7.asRight)).controlError(err => List(0, -1)) res0: List[Int] = List(42, 0, -1, 7)
-
abstract
def
monadErrorF: MonadError[F, E]
The MonadError instance for F[_]
-
abstract
def
monadG: Monad[G]
The Monad instance for G[_]
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
absolve[A](gea: G[Either[E, A]]): F[A]
The inverse of trial.
The inverse of trial.
Example:
scala> import cats._, data._, implicits._ scala> List(42.asRight, "Error!".asLeft, 7.asRight).absolve[EitherT[List, String, ?]] res0: EitherT[List, String, Int] = EitherT(List(Right(42), Left(Error!), Right(7)))
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
assure[A](ga: G[A])(error: (A) ⇒ Option[E]): F[A]
Turns a successful value into an error specified by the
error
function if it does not satisfy a given predicate.Turns a successful value into an error specified by the
error
function if it does not satisfy a given predicate.Example:
scala> import cats._, data._, implicits._ scala> List(42, 23, -4).assure[EitherT[List, String, ?]](n => if (n < 0) Some("Negative number: " + n) else None) res0: EitherT[List, String, Int] = EitherT(List(Right(42), Right(23), Left(Negative number: -4)))
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
control[A, B](fa: F[A])(f: (Either[E, A]) ⇒ G[B]): G[B]
Transform this
F[A]
value, by mapping either the error or the valid value to a new error-freeG[B]
. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
intercept[A](fa: F[A])(f: (E) ⇒ A): G[A]
Handle any error and recover from it, by mapping it to
A
.Handle any error and recover from it, by mapping it to
A
.Similar to
handleError
onApplicativeError
Example:
scala> import cats._, data._, implicits._ scala> EitherT(List(42.asRight, "Error!".asLeft, 7.asRight, "Another error".asLeft)).intercept(_ => 0) res0: List[Int] = List(42, 0, 7, 0)
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
trial[A](fa: F[A]): G[Either[E, A]]
Handle errors by turning them into scala.util.Either values inside
G
.Handle errors by turning them into scala.util.Either values inside
G
.If there is no error, then an
scala.util.Right
value will be returned.All non-fatal errors should be handled by this method.
Similar to
attempt
onApplicativeError
. -
def
trialT[A](fa: F[A]): EitherT[G, E, A]
Like trial, but returns inside the cats.data.EitherT monad transformer instead.
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )