final case class Good[+G](g: G) extends Or[G, Nothing] with Product with Serializable
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.
- g
the “good” value
- Source
- Or.scala
- Alphabetic
- By Inheritance
- Good
- Or
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
Good(g: G)
- g
the “good” 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[G, One[Nothing]]
Converts this
Orto anOrwith the sameGoodtype and aBadtype consisting ofOneparameterized by thisOr'sBadtype.Converts this
Orto anOrwith the sameGoodtype and aBadtype consisting ofOneparameterized by thisOr'sBadtype.For example, invoking the
accumulatingmethod on anInt Or ErrorMessagewould convert it to anInt Or One[ErrorMessage]. This result type, because theBadtype is anEvery, can be used with the mechanisms provided in traitAccumulationto accumulate errors.Note that if this
Oris already an accumulatingOr, the behavior of thisaccumulatingmethod does not change. For example, if you invokeaccumulatingon anInt Or One[ErrorMessage]you will be rewarded with anInt Or One[One[ErrorMessage]].- returns
this
Good, if thisOris aGood; or thisBadvalue wrapped in aOneif thisOris aBad.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
badMap[C](f: (Nothing) ⇒ C): Or[G, C]
Maps the given function to this
Or's value if it is aBador returnsthisif it is aGood. -
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
exists(p: (G) ⇒ Boolean): Boolean
Returns
trueif thisOris aGoodand the predicatepreturns true when applied to thisGood's value.Returns
trueif thisOris aGoodand the predicatepreturns true when applied to thisGood's value.Note: The
existsmethod will return the same result asforallif thisOris aGood, but the opposite result if thisOris aBad.- p
the predicate to apply to the
Goodvalue, if this is aGood- returns
the result of applying the passed predicate
pto theGoodvalue, if this is aGood, elsefalse
-
def
filter[C](f: (G) ⇒ Validation[C]): Or[G, C]
Returns this
Orif either 1) it is aBador 2) it is aGoodand applying the validation functionfto thisGood's value returnsPass; otherwise, returns a newBadcontaining the error value contained in theFailresulting from applying the validation functionfto thisGood's value.Returns this
Orif either 1) it is aBador 2) it is aGoodand applying the validation functionfto thisGood's value returnsPass; otherwise, returns a newBadcontaining the error value contained in theFailresulting from applying the validation functionfto thisGood's value.For examples of
filterused inforexpressions, see the main documentation for traitValidation.- f
the validation function to apply
- returns
a
Goodif thisOris aGoodthat passes the validation function, else aBad.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatMap[H, C](f: (G) ⇒ Or[H, C]): Or[H, C]
Returns the given function applied to the value contained in this
Orif it is aGood, or returnsthisif it is aBad.Returns the given function applied to the value contained in this
Orif it is aGood, or returnsthisif 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 thisBadis returned
-
def
fold[V](gf: (G) ⇒ V, bf: (Nothing) ⇒ V): V
Folds this
Orinto a value of typeVby applying the givengffunction if this is aGoodelse the givenbffunction if this is aBad.Folds this
Orinto a value of typeVby applying the givengffunction if this is aGoodelse the givenbffunction if this is aBad.- gf
the function to apply to this
Or'sGoodvalue, if it is aGood- bf
the function to apply to this
Or'sBadvalue, if it is aBad- returns
the result of applying the appropriate one of the two passed functions,
gfor bf, to thisOr's value
-
def
forall(p: (G) ⇒ Boolean): Boolean
Returns
trueif either thisOris aBador if the predicatepreturnstruewhen applied to thisGood's value.Returns
trueif either thisOris aBador if the predicatepreturnstruewhen applied to thisGood's value.Note: The
forallmethod will return the same result asexistsif thisOris aGood, but the opposite result if thisOris aBad.- p
the predicate to apply to the
Goodvalue, if this is aGood- returns
the result of applying the passed predicate
pto theGoodvalue, if this is aGood, elsetrue
-
def
foreach(f: (G) ⇒ Unit): Unit
Applies the given function f to the contained value if this
Oris aGood; does nothing if thisOris aBad. - val g: G
-
def
get: G
Returns the
Or's value if it is aGoodor throwsNoSuchElementExceptionif it is aBad. -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getOrElse[H >: G](default: ⇒ H): G
Returns, if this
OrisGood, thisGood's value; otherwise returns the result of evaluatingdefault. -
val
isBad: Boolean
Indicates whether this
Oris aBadIndicates whether this
Oris aBad- returns
true if this
Oris aBad,falseif it is aGood.
- Definition Classes
- Or
- val isGood: Boolean
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
map[H](f: (G) ⇒ H): Or[H, Nothing]
Maps the given function to this
Or's value if it is aGoodor returnsthisif 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
orBad[C]: Or[G, C]
Narrows the
Badtype of thisGoodto the given type.Narrows the
Badtype of thisGoodto the given type.Because
Orhas two types, but theGoodfactory method only takes a value of the “good” type, the Scala compiler will inferNothingfor theBadtype:scala> Good(3) res0: org.scalactic.Good[Int,Nothing] = Good(3)
Often
Nothingwill work fine, as it will be widened as soon as the compiler encounters a more specificBadtype. Sometimes, however, you may need to specify it. In such situations you can use thisorBadmethod, like this:scala> Good(3).orBad[String] res1: org.scalactic.Good[Int,String] = Good(3)
-
def
orElse[H >: G, C](alternative: ⇒ Or[H, C]): Or[G, Nothing]
Returns this
Orif it is aGood, otherwise returns the result of evaluating the passedalternative. -
def
recover[H >: G](f: (Nothing) ⇒ H): Or[H, Nothing]
Maps the given function to this
Or's value if it is aBad, transforming it into aGood, or returnsthisif it is already aGood.Maps the given function to this
Or's value if it is aBad, transforming it into aGood, or returnsthisif 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 thisGoodis returned
-
def
recoverWith[H >: G, C](f: (Nothing) ⇒ Or[H, C]): Or[H, C]
Maps the given function to this
Or's value if it is aBad, returning the result, or returnsthisif it is already aGood. -
def
swap: Or[Nothing, G]
Returns an
Orwith theGoodandBadtypes swapped:BadbecomesGoodandGoodbecomesBad.Returns an
Orwith theGoodandBadtypes swapped:BadbecomesGoodandGoodbecomesBad.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
Oris aGood, itsGoodvalue wrapped in aBad; if thisOris aBad, itsBadvalue wrapped in aGood.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toEither: Either[Nothing, G]
Returns an
Either: aRightcontaining theGoodvalue, if this is aGood; aLeftcontaining theBadvalue, if this is aBad.Returns an
Either: aRightcontaining theGoodvalue, if this is aGood; aLeftcontaining theBadvalue, if this is aBad.Note that values effectively “switch sides” when convering an
Orto anEither. If the type of theOron which you invoketoEitherisOr[Int, ErrorMessage]for example, the result will be anEither[ErrorMessage, Int]. The reason is that the convention forEitheris thatLeftis used for “bad” values andRightis used for “good” ones.- returns
this
Goodvalue, wrapped in aRight, or thisBadvalue, wrapped in aLeft.
-
def
toOption: Some[G]
Returns a
Somecontaining theGoodvalue, if thisOris aGood, elseNone. -
def
toSeq: IndexedSeq[G]
Returns an immutable
IndexedSeqcontaining theGoodvalue, if thisOris aGood, else an empty immutableIndexedSeq. -
def
toTry(implicit ev: <:<[Nothing, Throwable]): Success[G]
Returns a
Try: aSuccesscontaining theGoodvalue, if this is aGood; aFailurecontaining theBadvalue, if this is aBad.Returns a
Try: aSuccesscontaining theGoodvalue, if this is aGood; aFailurecontaining theBadvalue, if this is aBad.Note: This method can only be called if the
Badtype of thisOris a subclass ofThrowable(orThrowableitself).Note that values effectively “switch sides” when converting an
Orto anEither. If the type of theOron which you invoketoEitherisOr[Int, ErrorMessage]for example, the result will be anEither[ErrorMessage, Int]. The reason is that the convention forEitheris thatLeftis used for “bad” values andRightis used for “good” ones.- returns
this
Goodvalue, wrapped in aRight, or thisBadvalue, wrapped in aLeft.
-
def
transform[H, C](gf: (G) ⇒ Or[H, C], bf: (Nothing) ⇒ Or[H, C]): Or[H, C]
Transforms this
Orby applying the functiongfto thisOr'sGoodvalue if it is aGood, or by applyingbfto thisOr'sBadvalue if it is aBad.Transforms this
Orby applying the functiongfto thisOr'sGoodvalue if it is aGood, or by applyingbfto thisOr'sBadvalue if it is aBad.- gf
the function to apply to this
Or'sGoodvalue, if it is aGood- bf
the function to apply to this
Or'sBadvalue, if it is aBad- returns
the result of applying the appropriate one of the two passed functions,
gfor bf, to thisOr's value
-
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( ... )
-
def
withFilter[C >: Nothing](f: (G) ⇒ Validation[C]): Or[G, 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[G, Nothing]
The
asOrmethod has been deprecated and will be removed in a future version of Scalactic. Please remove invocations ofasOrin 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
asOrmethod has been deprecated and will be removed in a future version of Scalactic. Please remove invocations ofasOrin 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
- Good → 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).