Either
Either represents a value of two possible types: Left
or Right
. Example: compute()
function, which results
either in an integer value (in the case of success) or an error message of type string (in the case of failure).
If the result of compute() is 1, the value is Right(2)
.
If the result of compute() is error
, the value is Left('error')
.
By convention the success case is Right and the failure is Left.
Projecting Left
Either to a Right
have no effect on the left value. Similarly, projecting Right
Either
to a 'Left` have no effect one the right value.
#
ConstructionThere are two named constructors available: left
and right