Either α β is a sum type: either Left α or Right β.
Right-biased: Functor, Monad act on the Right case.
$$\text{Either}(\alpha, \beta) \cong \alpha + \beta$$
- left
{α : Type u}
{β : Type v}
: α → Either α β
The left case, typically representing an error or alternative.
- right
{α : Type u}
{β : Type v}
: β → Either α β
The right case, typically representing success.
Instances For
Equations
- Data.instBEqEither = { beq := Data.instBEqEither.beq }
Equations
- Data.instBEqEither.beq (Data.Either.left a) (Data.Either.left b) = (a == b)
- Data.instBEqEither.beq (Data.Either.right a) (Data.Either.right b) = (a == b)
- Data.instBEqEither.beq x✝¹ x✝ = false
Instances For
Equations
- Data.instOrdEither.ord (Data.Either.left a) (Data.Either.left b) = (compare a b).then Ordering.eq
- Data.instOrdEither.ord (Data.Either.left a) x✝ = Ordering.lt
- Data.instOrdEither.ord x✝ (Data.Either.left a) = Ordering.gt
- Data.instOrdEither.ord (Data.Either.right a) (Data.Either.right b) = (compare a b).then Ordering.eq
Instances For
Equations
- Data.instOrdEither = { compare := Data.instOrdEither.ord }
Equations
- Data.instReprEither = { reprPrec := Data.instReprEither.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Test if a value is Left.
$$\text{isLeft}(x) = \begin{cases} \text{true} & \text{if } x = \text{Left}(a) \\ \text{false} & \text{if } x = \text{Right}(b) \end{cases}$$
Equations
- (Data.Either.left a).isLeft = true
- (Data.Either.right a).isLeft = false
Instances For
Test if a value is Right.
$$\text{isRight}(x) = \neg\,\text{isLeft}(x)$$
Equations
Instances For
Extract from Left, or return a default.
$$\text{fromLeft}(d, \text{Left}(a)) = a, \quad \text{fromLeft}(d, \text{Right}(b)) = d$$
Equations
- Data.Either.fromLeft default (Data.Either.left a) = a
- Data.Either.fromLeft default (Data.Either.right a) = default
Instances For
Extract from Right, or return a default.
$$\text{fromRight}(d, \text{Right}(b)) = b, \quad \text{fromRight}(d, \text{Left}(a)) = d$$
Equations
- Data.Either.fromRight default (Data.Either.left a) = default
- Data.Either.fromRight default (Data.Either.right b) = b
Instances For
Case analysis: apply f to Left, g to Right.
$$\text{either}(f, g, \text{Left}(a)) = f(a), \quad \text{either}(f, g, \text{Right}(b)) = g(b)$$
Equations
- Data.Either.either f g (Data.Either.left a) = f a
- Data.Either.either f g (Data.Either.right a) = g a
Instances For
Map over the left component. $$\text{mapLeft}(f, \text{Left}(a)) = \text{Left}(f(a))$$
Equations
Instances For
Map over the right component. $$\text{mapRight}(f, \text{Right}(b)) = \text{Right}(f(b))$$
Equations
Instances For
Swap Left and Right.
$$\text{swap}(\text{Left}(a)) = \text{Right}(a), \quad \text{swap}(\text{Right}(b)) = \text{Left}(b)$$
Equations
Instances For
Partition a list of Either into lefts and rights.
Given $[e_1, \ldots, e_n]$, produces $(ls, rs)$ where $ls$ are the Left values
and $rs$ are the Right values.
Length preservation: $|ls| + |rs| = n$
Equations
- One or more equations did not get rendered due to their size.
Instances For
Partition preserves total count: $$|\text{fst}(\text{partitionEithers}(l))| + |\text{snd}(\text{partitionEithers}(l))| = |l|$$
Equations
- Data.Either.instFunctor = { map := fun {α_1 β : Type ?u.15} => Data.Either.mapRight }
Equations
- Data.Either.instPure = { pure := fun {α_1 : Type ?u.10} => Data.Either.right }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Data.Either.instMonad = { toApplicative := Data.Either.instApplicative, toBind := Data.Either.instBind }
Equations
- One or more equations did not get rendered due to their size.