Bad
Contains a “bad” value.
You can decide what “bad” means, but it is expected Bad will be commonly used to hold descriptions of an error (or several, accumulated errors). Some examples of possible error descriptions are String error messages, Int error codes, Throwable exceptions, or instances of a case class hierarchy designed to describe errors.
Value parameters
- b
-
the “bad” value
Attributes
- Source
- Or.scala
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Converts this Or to an Or with the same Good type and a Bad type consisting of One parameterized by this Or's Bad type.
Converts this Or to an Or with the same Good type and a Bad type consisting of One parameterized by this Or's Bad type.
For example, invoking the accumulating method on an Int Or ErrorMessage would convert it to an Int Or One[ErrorMessage]. This result type, because the Bad type is an Every, can be used with the mechanisms provided in trait Accumulation to accumulate errors.
Note that if this Or is already an accumulating Or, the behavior of this accumulating method does not change. For example, if you invoke accumulating on an Int Or One[ErrorMessage] you will be rewarded with an Int Or One[One[ErrorMessage]].
Attributes
- Returns
-
this
Good, if thisOris aGood; or thisBadvalue wrapped in aOneif thisOris aBad. - Source
- Or.scala
Maps the given function to this Or's value if it is a Bad or returns this if it is a Good.
Maps the given function to this Or's value if it is a Bad or returns this if it is a Good.
Value parameters
- f
-
the function to apply
Attributes
- Returns
-
if this is a
Bad, the result of applying the given function to the contained value wrapped in aBad, else thisGoodis returned - Source
- Or.scala
Returns true if this Or is a Good and the predicate p returns true when applied to this Good's value.
Returns true if this Or is a Good and the predicate p returns true when applied to this Good's value.
Note: The exists method will return the same result as forall if this Or is a Good, but the opposite result if this Or is a Bad.
Value parameters
- p
-
the predicate to apply to the
Goodvalue, if this is aGood
Attributes
- Returns
-
the result of applying the passed predicate
pto theGoodvalue, if this is aGood, elsefalse - Source
- Or.scala
Returns this Or if either 1) it is a Bad or 2) it is a Good and applying the validation function f to this Good's value returns Pass; otherwise, returns a new Bad containing the error value contained in the Fail resulting from applying the validation function f to this Good's value.
Returns this Or if either 1) it is a Bad or 2) it is a Good and applying the validation function f to this Good's value returns Pass; otherwise, returns a new Bad containing the error value contained in the Fail resulting from applying the validation function f to this Good's value.
For examples of filter used in for expressions, see the main documentation for trait Validation.
Value parameters
- f
-
the validation function to apply
Attributes
- Returns
-
a
Goodif thisOris aGoodthat passes the validation function, else aBad. - Source
- Or.scala
Returns the given function applied to the value contained in this Or if it is a Good, or returns this if it is a Bad.
Returns the given function applied to the value contained in this Or if it is a Good, or returns this if it is a Bad.
Value parameters
- f
-
the function to apply
Attributes
- Returns
-
if this is a
Good, the result of applying the given function to the contained value wrapped in aGood, else thisBadis returned - Source
- Or.scala
Folds this Or into a value of type V by applying the given gf function if this is a Good else the given bf function if this is a Bad.
Folds this Or into a value of type V by applying the given gf function if this is a Good else the given bf function if this is a Bad.
Value parameters
- bf
-
the function to apply to this
Or'sBadvalue, if it is aBad - gf
-
the function to apply to this
Or'sGoodvalue, if it is aGood
Attributes
- Returns
-
the result of applying the appropriate one of the two passed functions,
gfor bf, to thisOr's value - Source
- Or.scala
Returns true if either this Or is a Bad or if the predicate p returns true when applied to this Good's value.
Returns true if either this Or is a Bad or if the predicate p returns true when applied to this Good's value.
Note: The forall method will return the same result as exists if this Or is a Good, but the opposite result if this Or is a Bad.
Value parameters
- p
-
the predicate to apply to the
Goodvalue, if this is aGood
Attributes
- Returns
-
the result of applying the passed predicate
pto theGoodvalue, if this is aGood, elsetrue - Source
- Or.scala
Applies the given function f to the contained value if this Or is a Good; does nothing if this Or is a Bad.
Applies the given function f to the contained value if this Or is a Good; does nothing if this Or is a Bad.
Value parameters
- f
-
the function to apply
Attributes
- Source
- Or.scala
Returns the Or's value if it is a Good or throws NoSuchElementException if it is a Bad.
Returns the Or's value if it is a Good or throws NoSuchElementException if it is a Bad.
Attributes
- Returns
-
the contained value if this is a
Good - Throws
-
NoSuchElementException
if this is a
Bad - Source
- Or.scala
Returns, if this Or is Good, this Good's value; otherwise returns the result of evaluating default.
Returns, if this Or is Good, this Good's value; otherwise returns the result of evaluating default.
Value parameters
- default
-
the default expression to evaluate if this
Oris aBad
Attributes
- Returns
-
the contained value, if this
Oris aGood, else the result of evaluating the givendefault - Source
- Or.scala
Maps the given function to this Or's value if it is a Good or returns this if it is a Bad.
Maps the given function to this Or's value if it is a Good or returns this if it is a Bad.
Value parameters
- f
-
the function to apply
Attributes
- Returns
-
if this is a
Good, the result of applying the given function to the contained value wrapped in aGood, else thisBadis returned - Source
- Or.scala
Returns this Or if it is a Good, otherwise returns the result of evaluating the passed alternative.
Returns this Or if it is a Good, otherwise returns the result of evaluating the passed alternative.
Value parameters
- alternative
-
the alternative by-name to evaluate if this
Oris aBad
Attributes
- Returns
-
this
Or, if it is aGood, else the result of evaluatingalternative - Source
- Or.scala
Maps the given function to this Or's value if it is a Bad, transforming it into a Good, or returns this if it is already a Good.
Maps the given function to this Or's value if it is a Bad, transforming it into a Good, or returns this if it is already a Good.
Value parameters
- f
-
the function to apply
Attributes
- Returns
-
if this is a
Bad, the result of applying the given function to the contained value wrapped in aGood, else thisGoodis returned - Source
- Or.scala
Maps the given function to this Or's value if it is a Bad, returning the result, or returns this if it is already a Good.
Maps the given function to this Or's value if it is a Bad, returning the result, or returns this if it is already a Good.
Value parameters
- f
-
the function to apply
Attributes
- Returns
-
if this is a
Bad, the result of applying the given function to the contained value, else thisGoodis returned - Source
- Or.scala
Returns an Or with the Good and Bad types swapped: Bad becomes Good and Good becomes Bad.
Returns an Or with the Good and Bad types swapped: Bad becomes Good and Good becomes Bad.
Here's an example:
scala> val lyrics = Bad("Hey Jude, don't make it bad. Take a sad song and make it better.")
lyrics: org.scalactic.Bad[Nothing,String] =
Bad(Hey Jude, don't make it bad. Take a sad song and make it better.)
scala> lyrics.swap
res12: org.scalactic.Or[String,Nothing] =
Good(Hey Jude, don't make it bad. Take a sad song and make it better.)
Now that song will be rolling around in your head all afternoon. But at least it is a good song (thanks to swap).
Attributes
- Returns
-
if this
Oris aGood, itsGoodvalue wrapped in aBad; if thisOris aBad, itsBadvalue wrapped in aGood. - Source
- Or.scala
Returns an Either: a Right containing the Good value, if this is a Good; a Left containing the Bad value, if this is a Bad.
Returns an Either: a Right containing the Good value, if this is a Good; a Left containing the Bad value, if this is a Bad.
Note that values effectively “switch sides” when convering an Or to an Either. If the type of the Or on which you invoke toEither is Or[Int, ErrorMessage] for example, the result will be an Either[ErrorMessage, Int]. The reason is that the convention for Either is that Left is used for “bad” values and Right is used for “good” ones.
Attributes
- Returns
-
this
Goodvalue, wrapped in aRight, or thisBadvalue, wrapped in aLeft. - Source
- Or.scala
Returns a Some containing the Good value, if this Or is a Good, else None.
Returns a Some containing the Good value, if this Or is a Good, else None.
Attributes
- Returns
-
the contained “good” value wrapped in a
Some, if thisOris aGood;Noneif thisOris aBad. - Source
- Or.scala
Returns an immutable IndexedSeq containing the Good value, if this Or is a Good, else an empty immutable IndexedSeq.
Returns an immutable IndexedSeq containing the Good value, if this Or is a Good, else an empty immutable IndexedSeq.
Attributes
- Returns
-
the contained “good” value in a lone-element
Seqif thisOris aGood; an emptySeqif thisOris aBad. - Source
- Or.scala
Returns a Try: a Success containing the Good value, if this is a Good; a Failure containing the Bad value, if this is a Bad.
Returns a Try: a Success containing the Good value, if this is a Good; a Failure containing the Bad value, if this is a Bad.
Note: This method can only be called if the Bad type of this Or is a subclass of Throwable (or Throwable itself).
Note that values effectively “switch sides” when converting an Or to an Either. If the type of the Or on which you invoke toEither is Or[Int, ErrorMessage] for example, the result will be an Either[ErrorMessage, Int]. The reason is that the convention for Either is that Left is used for “bad” values and Right is used for “good” ones.
Attributes
- Returns
-
this
Goodvalue, wrapped in aRight, or thisBadvalue, wrapped in aLeft. - Source
- Or.scala
Transforms this Or by applying the function gf to this Or's Good value if it is a Good, or by applying bf to this Or's Bad value if it is a Bad.
Transforms this Or by applying the function gf to this Or's Good value if it is a Good, or by applying bf to this Or's Bad value if it is a Bad.
Value parameters
- bf
-
the function to apply to this
Or'sBadvalue, if it is aBad - gf
-
the function to apply to this
Or'sGoodvalue, if it is aGood
Attributes
- Returns
-
the result of applying the appropriate one of the two passed functions,
gfor bf, to thisOr's value - 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).
Attributes
- Deprecated
- true
- Definition Classes
- Source
- Or.scala
Inherited methods
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product