Sums up values inside disjunction, if both are left or right.
Sums up values inside disjunction, if both are left or right. Returns first left otherwise.
\/-(v1) +++ \/-(v2) → \/-(v1 + v2) \/-(v1) +++ -\/(v2) → -\/(v2) -\/(v1) +++ \/-(v2) → -\/(v1) -\/(v1) +++ -\/(v2) → -\/(v1 + v2)
If this disjunction is right, return the given X value, otherwise, return the X value given to the return value.
Compare two disjunction values for equality.
Run a validation function and back to disjunction again.
Run a validation function and back to disjunction again. Alias for validationed
Apply a function in the environment of the right of this disjunction.
Binary functor map on this disjunction.
Binary functor traverse on this disjunction.
Compare two disjunction values for ordering.
Ensures that the right value of this disjunction satisfies the given predicate, or returns left with the given value.
Return true
if this disjunction is a right value satisfying the given predicate.
Filter on the right of this disjunction.
Bind through the right of this disjunction.
Catamorphism.
Catamorphism. Run the first given function if left, otherwise, the second given function.
Fold on the right of this disjunction.
Return true
if this disjunction is a left value or the right value satisfies the given predicate.
Run the side-effect on the right of this disjunction.
Return the right value of this disjunction or the given default if left.
Return the right value of this disjunction or the given default if left. Alias for |
Return true
if this disjunction is left.
Return true
if this disjunction is right.
Run the given function on the left value.
Spin in tail-position on the left value of this disjunction.
Spin in tail-position on the right value of this disjunction.
Map on the right of this disjunction.
Return the value from whichever side of the disjunction is defined, given a commonly assignable type.
Return this if it is a right, otherwise, return the given value.
Return this if it is a right, otherwise, return the given value. Alias for |||
Run the given function on the left and return right with the result.
Run the given function on the left and return the result.
Show for a disjunction value.
Flip the left/right values in this disjunction.
Flip the left/right values in this disjunction. Alias for unary_~
Run the given function on this swapped value.
Run the given function on this swapped value. Alias for ~
Convert to a core scala.Either
at your own peril.
Return an empty list or list with one element on the right of this disjunction.
Return an empty maybe or option with one element on the right of this disjunction.
Return an empty maybe or option with one element on the right of this disjunction. Useful to sweep errors under the carpet.
Return an empty option or option with one element on the right of this disjunction.
Return an empty option or option with one element on the right of this disjunction. Useful to sweep errors under the carpet.
Return an empty stream or stream with one element on the right of this disjunction.
Convert to a These.
Traverse on the right of this disjunction.
Flip the left/right values in this disjunction.
Flip the left/right values in this disjunction. Alias for swap
Convert to a Validation.
Convert to a ValidationNel.
Run a validation function and back to disjunction again.
Run a validation function and back to disjunction again. Alias for @\?/
Return the right value of this disjunction or run the given function on the left.
Return the right value of this disjunction or the given default if left.
Return the right value of this disjunction or the given default if left. Alias for getOrElse
Return this if it is a right, otherwise, return the given value.
Return this if it is a right, otherwise, return the given value. Alias for orElse
Run the given function on this swapped value.
Run the given function on this swapped value. Alias for swapped
Represents a disjunction: a result that is either an
A
or aB
.An instance of
A
\/ B is either a -\/[A]
(aka a "left") or a \/-[B]
(aka a "right").A common use of a disjunction is to explicitly represent the possibility of failure in a result as opposed to throwing an exception. By convention, the left is used for errors and the 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
\/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
\/B
is isomorphic toscala.Either[A, B]
, but \/ is right-biased for all Scala versions, so methods such asmap
andflatMap
apply only in the context of the "right" case. This right bias makes \/ more convenient to use thanscala.Either
in a monadic context in Scala versions <2.12. Methods such asswap
,swapped
, andleftMap
provide functionality thatscala.Either
exposes through left projections.A
\/B
is also isomorphic to Validation[A, B]
. The subtle but important difference is that Applicative instances for Validation accumulates errors ("lefts") while Applicative instances for \/ fail fast on the first "left" they evaluate. This fail-fast behavior allows \/ to have lawful Monad instances that are consistent with their Applicative instances, while Validation cannot.