Class/Object

org.scalactic

Good

Related Docs: object Good | package scalactic

Permalink

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
Linear Supertypes
Or[G, Nothing], Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Good
  2. Or
  3. Serializable
  4. Serializable
  5. Product
  6. Equals
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Good(g: G)

    Permalink

    g

    the “good” value

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def accumulating: Or[G, One[Nothing]]

    Permalink

    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]].

    returns

    this Good, if this Or is a Good; or this Bad value wrapped in a One if this Or is a Bad.

    Definition Classes
    GoodOr
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def badMap[C](f: (Nothing) ⇒ C): Or[G, C]

    Permalink

    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.

    f

    the function to apply

    returns

    if this is a Bad, the result of applying the given function to the contained value wrapped in a Bad, else this Good is returned

    Definition Classes
    GoodOr
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  9. def exists(p: (G) ⇒ Boolean): Boolean

    Permalink

    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.

    p

    the predicate to apply to the Good value, if this is a Good

    returns

    the result of applying the passed predicate p to the Good value, if this is a Good, else false

    Definition Classes
    GoodOr
  10. def filter[C](f: (G) ⇒ Validation[C]): Or[G, C]

    Permalink

    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.

    f

    the validation function to apply

    returns

    a Good if this Or is a Good that passes the validation function, else a Bad.

    Definition Classes
    GoodOr
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def flatMap[H, C](f: (G) ⇒ Or[H, C]): Or[H, C]

    Permalink

    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.

    f

    the function to apply

    returns

    if this is a Good, the result of applying the given function to the contained value wrapped in a Good, else this Bad is returned

    Definition Classes
    GoodOr
  13. def fold[V](gf: (G) ⇒ V, bf: (Nothing) ⇒ V): V

    Permalink

    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.

    gf

    the function to apply to this Or's Good value, if it is a Good

    bf

    the function to apply to this Or's Bad value, if it is a Bad

    returns

    the result of applying the appropriate one of the two passed functions, gf or bf, to this Or's value

    Definition Classes
    GoodOr
  14. def forall(p: (G) ⇒ Boolean): Boolean

    Permalink

    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.

    p

    the predicate to apply to the Good value, if this is a Good

    returns

    the result of applying the passed predicate p to the Good value, if this is a Good, else true

    Definition Classes
    GoodOr
  15. def foreach(f: (G) ⇒ Unit): Unit

    Permalink

    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.

    f

    the function to apply

    Definition Classes
    GoodOr
  16. val g: G

    Permalink

    the “good” value

  17. def get: G

    Permalink

    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.

    returns

    the contained value if this is a Good

    Definition Classes
    GoodOr
    Exceptions thrown

    NoSuchElementException if this is a Bad

  18. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  19. def getOrElse[H >: G](default: ⇒ H): G

    Permalink

    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.

    default

    the default expression to evaluate if this Or is a Bad

    returns

    the contained value, if this Or is a Good, else the result of evaluating the given default

    Definition Classes
    GoodOr
  20. val isBad: Boolean

    Permalink

    Indicates whether this Or is a Bad

    Indicates whether this Or is a Bad

    returns

    true if this Or is a Bad, false if it is a Good.

    Definition Classes
    Or
  21. val isGood: Boolean

    Permalink

    Indicates whether this Or is a Good

    Indicates whether this Or is a Good

    returns

    true if this Or is a Good, false if it is a Bad.

    Definition Classes
    GoodOr
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. def map[H](f: (G) ⇒ H): Or[H, Nothing]

    Permalink

    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.

    f

    the function to apply

    returns

    if this is a Good, the result of applying the given function to the contained value wrapped in a Good, else this Bad is returned

    Definition Classes
    GoodOr
  24. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  25. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. def orBad[C]: Or[G, C]

    Permalink

    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)
    

  28. def orElse[H >: G, C](alternative: ⇒ Or[H, C]): Or[G, Nothing]

    Permalink

    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.

    alternative

    the alternative by-name to evaluate if this Or is a Bad

    returns

    this Or, if it is a Good, else the result of evaluating alternative

    Definition Classes
    GoodOr
  29. def recover[H >: G](f: (Nothing) ⇒ H): Or[H, Nothing]

    Permalink

    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.

    f

    the function to apply

    returns

    if this is a Bad, the result of applying the given function to the contained value wrapped in a Good, else this Good is returned

    Definition Classes
    GoodOr
  30. def recoverWith[H >: G, C](f: (Nothing) ⇒ Or[H, C]): Or[H, C]

    Permalink

    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.

    f

    the function to apply

    returns

    if this is a Bad, the result of applying the given function to the contained value, else this Good is returned

    Definition Classes
    GoodOr
  31. def swap: Or[Nothing, G]

    Permalink

    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).

    returns

    if this Or is a Good, its Good value wrapped in a Bad; if this Or is a Bad, its Bad value wrapped in a Good.

    Definition Classes
    GoodOr
  32. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  33. def toEither: Either[Nothing, G]

    Permalink

    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.

    returns

    this Good value, wrapped in a Right, or this Bad value, wrapped in a Left.

    Definition Classes
    GoodOr
  34. def toOption: Some[G]

    Permalink

    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.

    returns

    the contained “good” value wrapped in a Some, if this Or is a Good; None if this Or is a Bad.

    Definition Classes
    GoodOr
  35. def toSeq: IndexedSeq[G]

    Permalink

    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.

    returns

    the contained “good” value in a lone-element Seq if this Or is a Good; an empty Seq if this Or is a Bad.

    Definition Classes
    GoodOr
  36. def toTry(implicit ev: <:<[Nothing, Throwable]): Success[G]

    Permalink

    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.

    returns

    this Good value, wrapped in a Right, or this Bad value, wrapped in a Left.

    Definition Classes
    GoodOr
  37. def transform[H, C](gf: (G) ⇒ Or[H, C], bf: (Nothing) ⇒ Or[H, C]): Or[H, C]

    Permalink

    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.

    gf

    the function to apply to this Or's Good value, if it is a Good

    bf

    the function to apply to this Or's Bad value, if it is a Bad

    returns

    the result of applying the appropriate one of the two passed functions, gf or bf, to this Or's value

    Definition Classes
    GoodOr
  38. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. def withFilter[C >: Nothing](f: (G) ⇒ Validation[C]): Or[G, C]

    Permalink

    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

  1. def asOr: Or[G, Nothing]

    Permalink

    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).

    Definition Classes
    GoodOr
    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).

Inherited from Or[G, Nothing]

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped