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.
Represents a right-biased disjunction that is either an
A
or aB
.An instance of
A Xor B
is either aLeft[A]
or aRight[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 extendException
.A Xor B
is isomorphic toscala.Either[A, B]
, but Xor is right-biased, so methods such asmap
andflatMap
apply only in the context of the "right" case. This right bias makes Xor more convenient to use thanscala.Either
in a monadic context. Methods such asswap
, andleftMap
provide functionality thatscala.Either
exposes through left projections.