final case class Bad[+B](b: B) extends Or[Nothing, B] with Product with Serializable
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.
- b
the “bad” value
- Source
- Or.scala
- Alphabetic
- By Inheritance
- Bad
- Or
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Bad(b: B)
- b
the “bad” value
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 accumulating: Or[Nothing, One[B]]
Converts this
Or
to anOr
with the sameGood
type and aBad
type consisting ofOne
parameterized by thisOr
'sBad
type.Converts this
Or
to anOr
with the sameGood
type and aBad
type consisting ofOne
parameterized by thisOr
'sBad
type.For example, invoking the
accumulating
method on anInt Or ErrorMessage
would convert it to anInt Or One[ErrorMessage]
. This result type, because theBad
type is anEvery
, can be used with the mechanisms provided in traitAccumulation
to accumulate errors.Note that if this
Or
is already an accumulatingOr
, the behavior of thisaccumulating
method does not change. For example, if you invokeaccumulating
on anInt Or One[ErrorMessage]
you will be rewarded with anInt Or One[One[ErrorMessage]]
.- returns
this
Good
, if thisOr
is aGood
; or thisBad
value wrapped in aOne
if thisOr
is aBad
.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- val b: B
- def badMap[C](f: (B) => C): Or[Nothing, C]
Maps the given function to this
Or
's value if it is aBad
or returnsthis
if it is aGood
. - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def exists(p: (Nothing) => Boolean): Boolean
Returns
true
if thisOr
is aGood
and the predicatep
returns true when applied to thisGood
's value.Returns
true
if thisOr
is aGood
and the predicatep
returns true when applied to thisGood
's value.Note: The
exists
method will return the same result asforall
if thisOr
is aGood
, but the opposite result if thisOr
is aBad
.- p
the predicate to apply to the
Good
value, if this is aGood
- returns
the result of applying the passed predicate
p
to theGood
value, if this is aGood
, elsefalse
- def filter[C >: B](f: (Nothing) => Validation[C]): Or[Nothing, C]
Returns this
Or
if either 1) it is aBad
or 2) it is aGood
and applying the validation functionf
to thisGood
's value returnsPass
; otherwise, returns a newBad
containing the error value contained in theFail
resulting from applying the validation functionf
to thisGood
's value.Returns this
Or
if either 1) it is aBad
or 2) it is aGood
and applying the validation functionf
to thisGood
's value returnsPass
; otherwise, returns a newBad
containing the error value contained in theFail
resulting from applying the validation functionf
to thisGood
's value.For examples of
filter
used infor
expressions, see the main documentation for traitValidation
.- f
the validation function to apply
- returns
a
Good
if thisOr
is aGood
that passes the validation function, else aBad
.
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[H, C >: B](f: (Nothing) => Or[H, C]): Or[H, C]
Returns the given function applied to the value contained in this
Or
if it is aGood
, or returnsthis
if it is aBad
.Returns the given function applied to the value contained in this
Or
if it is aGood
, or returnsthis
if it is aBad
.- f
the function to apply
- returns
if this is a
Good
, the result of applying the given function to the contained value wrapped in aGood
, else thisBad
is returned
- def fold[V](gf: (Nothing) => V, bf: (B) => V): V
Folds this
Or
into a value of typeV
by applying the givengf
function if this is aGood
else the givenbf
function if this is aBad
.Folds this
Or
into a value of typeV
by applying the givengf
function if this is aGood
else the givenbf
function if this is aBad
.- gf
the function to apply to this
Or
'sGood
value, if it is aGood
- bf
the function to apply to this
Or
'sBad
value, if it is aBad
- returns
the result of applying the appropriate one of the two passed functions,
gf
or bf, to thisOr
's value
- def forall(p: (Nothing) => Boolean): Boolean
Returns
true
if either thisOr
is aBad
or if the predicatep
returnstrue
when applied to thisGood
's value.Returns
true
if either thisOr
is aBad
or if the predicatep
returnstrue
when applied to thisGood
's value.Note: The
forall
method will return the same result asexists
if thisOr
is aGood
, but the opposite result if thisOr
is aBad
.- p
the predicate to apply to the
Good
value, if this is aGood
- returns
the result of applying the passed predicate
p
to theGood
value, if this is aGood
, elsetrue
- def foreach(f: (Nothing) => Unit): Unit
Applies the given function f to the contained value if this
Or
is aGood
; does nothing if thisOr
is aBad
. - def get: Nothing
Returns the
Or
's value if it is aGood
or throwsNoSuchElementException
if it is aBad
. - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def getOrElse[H](default: => H): H
Returns, if this
Or
isGood
, thisGood
's value; otherwise returns the result of evaluatingdefault
. - val isBad: Boolean
- val isGood: Boolean
Indicates whether this
Or
is aGood
Indicates whether this
Or
is aGood
- returns
true if this
Or
is aGood
,false
if it is aBad
.
- Definition Classes
- Or
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[H](f: (Nothing) => H): Or[H, B]
Maps the given function to this
Or
's value if it is aGood
or returnsthis
if it is aBad
. - 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()
- def orElse[H, C >: B](alternative: => Or[H, C]): Or[H, C]
Returns this
Or
if it is aGood
, otherwise returns the result of evaluating the passedalternative
. - def productElementNames: Iterator[String]
- Definition Classes
- Product
- def recover[H](f: (B) => H): Or[H, B]
Maps the given function to this
Or
's value if it is aBad
, transforming it into aGood
, or returnsthis
if it is already aGood
.Maps the given function to this
Or
's value if it is aBad
, transforming it into aGood
, or returnsthis
if it is already aGood
.- f
the function to apply
- returns
if this is a
Bad
, the result of applying the given function to the contained value wrapped in aGood
, else thisGood
is returned
- def recoverWith[H, C](f: (B) => Or[H, C]): Or[H, C]
Maps the given function to this
Or
's value if it is aBad
, returning the result, or returnsthis
if it is already aGood
. - def swap: Or[B, Nothing]
Returns an
Or
with theGood
andBad
types swapped:Bad
becomesGood
andGood
becomesBad
.Returns an
Or
with theGood
andBad
types swapped:Bad
becomesGood
andGood
becomesBad
.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
).- returns
if this
Or
is aGood
, itsGood
value wrapped in aBad
; if thisOr
is aBad
, itsBad
value wrapped in aGood
.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toEither: Either[B, Nothing]
Returns an
Either
: aRight
containing theGood
value, if this is aGood
; aLeft
containing theBad
value, if this is aBad
.Returns an
Either
: aRight
containing theGood
value, if this is aGood
; aLeft
containing theBad
value, if this is aBad
.Note that values effectively “switch sides” when convering an
Or
to anEither
. If the type of theOr
on which you invoketoEither
isOr[Int, ErrorMessage]
for example, the result will be anEither[ErrorMessage, Int]
. The reason is that the convention forEither
is thatLeft
is used for “bad” values andRight
is used for “good” ones.- returns
this
Good
value, wrapped in aRight
, or thisBad
value, wrapped in aLeft
.
- def toOption: None.type
Returns a
Some
containing theGood
value, if thisOr
is aGood
, elseNone
. - def toSeq: IndexedSeq[Nothing]
Returns an immutable
IndexedSeq
containing theGood
value, if thisOr
is aGood
, else an empty immutableIndexedSeq
. - def toTry(implicit ev: <:<[B, Throwable]): Failure[Nothing]
Returns a
Try
: aSuccess
containing theGood
value, if this is aGood
; aFailure
containing theBad
value, if this is aBad
.Returns a
Try
: aSuccess
containing theGood
value, if this is aGood
; aFailure
containing theBad
value, if this is aBad
.Note: This method can only be called if the
Bad
type of thisOr
is a subclass ofThrowable
(orThrowable
itself).Note that values effectively “switch sides” when converting an
Or
to anEither
. If the type of theOr
on which you invoketoEither
isOr[Int, ErrorMessage]
for example, the result will be anEither[ErrorMessage, Int]
. The reason is that the convention forEither
is thatLeft
is used for “bad” values andRight
is used for “good” ones.- returns
this
Good
value, wrapped in aRight
, or thisBad
value, wrapped in aLeft
.
- def transform[H, C](gf: (Nothing) => Or[H, C], bf: (B) => Or[H, C]): Or[H, C]
Transforms this
Or
by applying the functiongf
to thisOr
'sGood
value if it is aGood
, or by applyingbf
to thisOr
'sBad
value if it is aBad
.Transforms this
Or
by applying the functiongf
to thisOr
'sGood
value if it is aGood
, or by applyingbf
to thisOr
'sBad
value if it is aBad
.- gf
the function to apply to this
Or
'sGood
value, if it is aGood
- bf
the function to apply to this
Or
'sBad
value, if it is aBad
- returns
the result of applying the appropriate one of the two passed functions,
gf
or bf, to thisOr
's value
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withFilter[C >: B](f: (Nothing) => Validation[C]): Or[Nothing, C]
Currently just forwards to filter, and therefore, returns the same result.
Currently just forwards to filter, and therefore, returns the same result.
- Definition Classes
- Or
Deprecated Value Members
- def asOr: Or[Nothing, B]
The
asOr
method has been deprecated and will be removed in a future version of Scalactic. Please remove invocations ofasOr
in expressions of typeGood(value).orBad[Type]
andGood[Type].orBad(value)
(which now return a type already widened toOr
), 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 ofasOr
in expressions of typeGood(value).orBad[Type]
andGood[Type].orBad(value)
(which now return a type already widened toOr
), otherwise please use a type annotation to widen the type, such as:(Good(3): Int Or ErrorMessage)
.- Definition Classes
- Bad → Or
- Annotations
- @deprecated
- Deprecated
The asOr is no longer needed because Good(value).orBad[Type] and Good[Type].orBad(value) now return Or. You can delete invocations of asOr in those cases, otherwise, please use a type annotation to widen the type, like (Good(3): Int Or ErrorMessage).