Class/Object

cats.data

Xor

Related Docs: object Xor | package data

Permalink

sealed abstract class Xor[+A, +B] extends Product with Serializable

Represents a right-biased disjunction that is either an A or a B.

An instance of A Xor B is either a Left[A] or a Right[B].

A common use of Xor is to explicitly represent the possibility of failure in a result as opposed to throwing an exception. By convention, Left is used for errors and Right is reserved for successes. For example, a function that attempts to parse an integer from a string may have a return type of NumberFormatException Xor Int. However, since there is no need to actually throw an exception, the type (A) chosen for the "left" could be any type representing an error and has no need to actually extend Exception.

A Xor B is isomorphic to scala.Either[A, B], but Xor is right-biased, so methods such as map and flatMap apply only in the context of the "right" case. This right bias makes Xor more convenient to use than scala.Either in a monadic context. Methods such as swap, and leftMap provide functionality that scala.Either exposes through left projections.

Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Xor
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def canEqual(that: Any): Boolean

    Permalink
    Definition Classes
    Equals
  2. abstract def productArity: Int

    Permalink
    Definition Classes
    Product
  3. abstract def productElement(n: Int): Any

    Permalink
    Definition Classes
    Product

Concrete 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 ===[AA >: A, BB >: B](that: Xor[AA, BB])(implicit AA: Eq[AA], BB: Eq[BB]): Boolean

    Permalink
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def bimap[C, D](fa: (A) ⇒ C, fb: (B) ⇒ D): Xor[C, D]

    Permalink
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def combine[AA >: A, BB >: B](that: Xor[AA, BB])(implicit AA: Semigroup[AA], BB: Semigroup[BB]): Xor[AA, BB]

    Permalink
  9. def compare[AA >: A, BB >: B](that: Xor[AA, BB])(implicit AA: Order[AA], BB: Order[BB]): Int

    Permalink
  10. def ensure[AA >: A](onFailure: ⇒ AA)(f: (B) ⇒ Boolean): Xor[AA, B]

    Permalink
  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def exists(f: (B) ⇒ Boolean): Boolean

    Permalink
  14. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. def flatMap[AA >: A, D](f: (B) ⇒ Xor[AA, D]): Xor[AA, D]

    Permalink
  16. def fold[C](fa: (A) ⇒ C, fb: (B) ⇒ C): C

    Permalink
  17. def foldLeft[C](c: C)(f: (C, B) ⇒ C): C

    Permalink
  18. def foldRight[C](lc: Eval[C])(f: (B, Eval[C]) ⇒ Eval[C]): Eval[C]

    Permalink
  19. def forall(f: (B) ⇒ Boolean): Boolean

    Permalink
  20. def foreach(f: (B) ⇒ Unit): Unit

    Permalink
  21. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  22. def getOrElse[BB >: B](default: ⇒ BB): BB

    Permalink
  23. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  24. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  25. def isLeft: Boolean

    Permalink
  26. def isRight: Boolean

    Permalink
  27. def leftMap[C](f: (A) ⇒ C): Xor[C, B]

    Permalink
  28. def map[D](f: (B) ⇒ D): Xor[A, D]

    Permalink
  29. def merge[AA >: A](implicit ev: <:<[B, AA]): AA

    Permalink
  30. final def ne(arg0: AnyRef): Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
  33. def orElse[C, BB >: B](fallback: ⇒ Xor[C, BB]): Xor[C, BB]

    Permalink
  34. def partialCompare[AA >: A, BB >: B](that: Xor[AA, BB])(implicit AA: PartialOrder[AA], BB: PartialOrder[BB]): Double

    Permalink
  35. def productIterator: Iterator[Any]

    Permalink
    Definition Classes
    Product
  36. def productPrefix: String

    Permalink
    Definition Classes
    Product
  37. def recover[BB >: B](pf: PartialFunction[A, BB]): Xor[A, BB]

    Permalink
  38. def recoverWith[AA >: A, BB >: B](pf: PartialFunction[A, Xor[AA, BB]]): Xor[AA, BB]

    Permalink
  39. def show[AA >: A, BB >: B](implicit AA: Show[AA], BB: Show[BB]): String

    Permalink
  40. def swap: Xor[B, A]

    Permalink
  41. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  42. def to[F[_], BB >: B](implicit monoidKF: MonoidK[F], applicativeF: Applicative[F]): F[BB]

    Permalink
  43. def toEither: Either[A, B]

    Permalink
  44. def toIor: Ior[A, B]

    Permalink
  45. def toList: List[B]

    Permalink
  46. def toOption: Option[B]

    Permalink
  47. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  48. def toValidated: Validated[A, B]

    Permalink
  49. def toValidatedNel[AA >: A]: ValidatedNel[AA, B]

    Permalink

    Returns a ValidatedNel representation of this disjunction with the Left value as a single element on the Invalid side of the NonEmptyList.

  50. def traverse[F[_], AA >: A, D](f: (B) ⇒ F[D])(implicit F: Applicative[F]): F[Xor[AA, D]]

    Permalink
  51. def valueOr[BB >: B](f: (A) ⇒ BB): BB

    Permalink
  52. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  55. def withValidated[AA, BB](f: (Validated[A, B]) ⇒ Validated[AA, BB]): Xor[AA, BB]

    Permalink

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped