Contains a “good” value.
You can decide what “good” means, but it is expected Good
will be commonly used
to hold valid results for processes that may fail with an error instead of producing a valid result.
Value members
Concrete methods
Narrows the Bad
type of this Good
to the given type.
Narrows the Bad
type of this Good
to the given type.
Because Or
has two types, but the Good
factory method only takes a value of the “good” type, the Scala compiler will
infer Nothing
for the Bad
type:
scala> Good(3) res0: org.scalactic.Good[Int,Nothing] = Good(3)
Often Nothing
will work fine, as it will be widened as soon as the compiler encounters a more specific Bad
type.
Sometimes, however, you may need to specify it. In such situations you can use this orBad
method, like this:
scala> Good(3).orBad[String] res1: org.scalactic.Good[Int,String] = Good(3)
- Source:
- Or.scala
Deprecated methods
The asOr
method has been deprecated and will be removed in a future version of Scalactic.
Please remove invocations of asOr
in expressions of type Good(value).orBad[Type]
and
Good[Type].orBad(value)
(which now return a type already widened to Or
), otherwise please
use a type annotation to widen the type, such as: (Good(3): Int Or ErrorMessage)
.
The asOr
method has been deprecated and will be removed in a future version of Scalactic.
Please remove invocations of asOr
in expressions of type Good(value).orBad[Type]
and
Good[Type].orBad(value)
(which now return a type already widened to Or
), otherwise please
use a type annotation to widen the type, such as: (Good(3): Int Or ErrorMessage)
.
- Deprecated
- Definition Classes
- Source:
- Or.scala