Either monads support either a L (left) or a R (right) value. L is traditionally used as an error carrier, and any Either monad
carrying an L will short-cut any bind operations and return the L (kinda like an Exception). However, they're not only for that,
and can be used to carry an alternative value which could be mapped using BiMap, or MapLeft.
You can construct an Either using the constructor functions in the Prelude:
Either<string, int> ma = Left<string, int>("this is an error");
Either<string, int> mb = Right<string, int>(123);
There are also convenience types called Left and Right, that don't need both generics providing. They can often make it a little
easier to work with Either:
Either<string, int> ma = Left("this is an error");
Either<string, int> mb = Right(123);
It uses implicit casts to work out what the type should be. Note, if you're having trouble getting the types resolved, just specify the type parameters.
Contents
- Either <L, R>
- IsRight
- IsLeft
- | (Either<L, R> lhs, Either<L, R> rhs)
- Match <B> (Func<L, B> Left, Func<R, B> Right)
- Match (Action<L> Left, Action<R> Right)
- IfLeft (Func<R> Left)
- IfLeft (Func<L, R> leftMap)
- IfLeft (R rightValue)
- IfLeft (Action<L> Left)
- IfRight (Action<R> Right)
- IfRight (L leftValue)
- IfRight (Func<L> Right)
- IfRight (Func<R, L> rightMap)
- CompareTo (object? obj)
- LeftSpan ()
- RightSpan ()
- AsEnumerable ()
- ToIterable ()
- ToList ()
- ToArray ()
- ToSeq ()
- ToOption ()
- ToEff (Func<L, Error> Left)
- ToIO ()
- < (Either<L, R> lhs, Fail<L> rhs)
- <= (Either<L, R> lhs, Fail<L> rhs)
- > (Either<L, R> lhs, Fail<L> rhs)
- >= (Either<L, R> lhs, Fail<L> rhs)
- < (Either<L, R> lhs, Pure<R> rhs)
- <= (Either<L, R> lhs, Pure<R> rhs)
- > (Either<L, R> lhs, Pure<R> rhs)
- >= (Either<L, R> lhs, Pure<R> rhs)
- < (Fail<L> lhs, Either<L, R> rhs)
- <= (Fail<L> lhs, Either<L, R> rhs)
- > (Fail<L> lhs, Either<L, R>rhs)
- >= (Fail<L> lhs, Either<L, R> rhs)
- < (Pure<R> lhs, Either<L, R> rhs)
- <= (Pure<R> lhs, Either<L, R> rhs)
- > (Pure<R> lhs, Either<L, R> rhs)
- >= (Pure<R> lhs, Either<L, R> rhs)
- < (Either<L, R> lhs, Either<L, R> rhs)
- <= (Either<L, R> lhs, Either<L, R> rhs)
- > (Either<L, R> lhs, Either<L, R> rhs)
- >= (Either<L, R> lhs, Either<L, R> rhs)
- == (Either<L, R> lhs, Fail<L> rhs)
- == (Either<L, R> lhs, Pure<R> rhs)
- == (Fail<L> lhs, Either<L, R> rhs)
- == (Pure<R> lhs, Either<L, R> rhs)
- != (Either<L, R> lhs, Fail<L> rhs)
- != (Either<L, R> lhs, Pure<R> rhs)
- != (Fail<L> lhs, Either<L, R> rhs)
- != (Pure<R> lhs, Either<L, R> rhs)
- true (Either<L, R> value)
- false (Either<L, R> value)
- CompareTo (Either<L, R> other)
- CompareTo <OrdR> (Either<L, R> other)
- CompareTo <OrdL, OrdR> (Either<L, R> other)
- CompareTo (Fail<L> other)
- CompareTo (Pure<R> other)
- CompareTo (R? other)
- CompareTo (L? other)
- Equals (R? other)
- Equals (L? other)
- Equals (Either<L, R>? other)
- Equals <EqR> (Either<L, R> other)
- Equals <EqL, EqR> (Either<L, R> other)
- GetHashCode ()
- Equals (Fail<L> other)
- Equals (Pure<R> other)
- MatchUntyped <Res> (Func<object?, Res> Left, Func<object?, Res> Right)
- GetUnderlyingRightType ()
- GetUnderlyingLeftType ()
- GetUnderlyingType ()
- Swap ()
- ForAll (Func<R, bool> Right)
- BiForAll (Func<L, bool> Left, Func<R, bool> Right)
- Fold <S> (S state, Func<S, R, S> Right)
- BiFold <S> (S state, Func<S, L, S> Left, Func<S, R, S> Right)
- Exists (Func<R, bool> pred)
- Do (Action<R> f)
- Traverse <F, B> (Func<R, K<F, B>> f)
- Map <B> (Func<R, B> f)
- MapLeft <B> (Func<L, B> f)
- BiMap <L2, R2> (Func<L, L2> Left, Func<R, R2> Right)
- Bind <B> (Func<R, Either<L, B>> f)
- Bind <B> (Func<R, K<Either<L>, B>> f)
- BiBind <L2, R2> (Func<L, Either<L2, R2>> Left, Func<R, Either<L2, R2>> Right)
- BindLeft <L2> (Func<L, Either<L2, R>> f)
- Select <U> (Func<R, U> f)
- SelectMany <S, T> (Func<R, Either<L, S>> bind, Func<R, S, T> project)
- SelectMany (Func<R, Guard<L, Unit>> f)
- SelectMany <C> (Func<R, Guard<L, Unit>> bind, Func<R, Unit, C> project)
- Bind <B> (Func<R, Pure<B>> f)
- Bind (Func<R, Fail<L>> f)
- SelectMany <B, C> (Func<R, Pure<B>> bind, Func<R, B, C> project)
- SelectMany <B, C> (Func<R, Fail<L>> bind, Func<R, B, C> _)
- RightToList ()
- RightToArray ()
- RightToSeq ()
- EitherContext <L, R, Ret>
- EitherUnitContext <L, R>
- Either <L, R>
- Left (L Value)
- IsRight
- IsLeft
- Match <B> (Func<L, B> Left, Func<R, B> Right)
- ToString ()
- GetHashCode ()
- LeftSpan ()
- RightSpan ()
- AsEnumerable ()
- CompareTo <OrdL, OrdR> (Either<L, R> other)
- Equals <EqL, EqR> (Either<L, R> other)
- Map <B> (Func<R, B> f)
- BiMap <L2, R2> (Func<L, L2> Left, Func<R, R2> Right)
- Bind <B> (Func<R, Either<L, B>> f)
- BiBind <L2, R2> ( Func<L, Either<L2, R2>> Left, Func<R, Either<L2, R2>> Right)
- Either
- Either <L, R>
- Right (R Value)
- IsRight
- IsLeft
- Match <B> (Func<L, B> Left, Func<R, B> Right)
- ToString ()
- GetHashCode ()
- LeftSpan ()
- RightSpan ()
- AsEnumerable ()
- CompareTo <OrdL, OrdR> (Either<L, R> other)
- Equals <EqL, EqR> (Either<L, R> other)
- Map <B> (Func<R, B> f)
- BiMap <L2, R2> (Func<L, L2> Left, Func<R, R2> Right)
- Bind <B> (Func<R, Either<L, B>> f)
- BiBind <L2, R2> ( Func<L, Either<L2, R2>> Left, Func<R, Either<L2, R2>> Right)
- IEither
Sub modules
| Extensions |
| Operators |
| Prelude |
| Trait |
Holds one of two values Left or Right. Usually, Left is considered wrong or in-error, and
Right is, well, right - as in correct. When the Either is in a Left state, it cancels
computations like bind or map, etc. So, you can see Left as an 'early out, with a message'.
Unlike Option that has None as its alternative value (i.e. it has an 'early out, but no message').
NOTE: If you use Filter or Where (or where in a LINQ expression) with Either, then the Either
will be put into a Bottom state [if the predicate returns false]. When it's in this state it is
neither Right nor Left. And any usage could trigger a BottomException. So be aware of the issue
of filtering Either.
Also note, when the Either is in a Bottom state, some operations on it will continue to give valid
results or return another Either in the Bottom state and not throw. This is so a filtered Either
doesn't needlessly break expressions and could be rescued into something useful via Match.
Parameters
| type | L | Left |
| type | R | Right |
Properties
Methods
method B Match <B> (Func<L, B> Left, Func<R, B> Right) Source #
Invokes the Right or Left function depending on the state of the Either
Parameters
| type | B | Return type |
| param | Left | Function to invoke if in a Left state |
| param | Right | Function to invoke if in a Right state |
| returns | The return value of the invoked function | |
method Unit Match (Action<L> Left, Action<R> Right) Source #
Invokes the Right or Left action depending on the state of the Either
Parameters
| param | Right | Action to invoke if in a Right state |
| param | Left | Action to invoke if in a Left state |
| returns | Unit | |
method R IfLeft (Func<R> Left) Source #
Executes the Left function if the Either is in a Left state. Returns the Right value if the Either is in a Right state.
Parameters
| param | Left | Function to generate a Right value if in the Left state |
| returns | Returns an unwrapped Right value | |
method R IfLeft (Func<L, R> leftMap) Source #
Executes the leftMap function if the Either is in a Left state. Returns the Right value if the Either is in a Right state.
Parameters
| param | leftMap | Function to generate a Right value if in the Left state |
| returns | Returns an unwrapped Right value | |
method R IfLeft (R rightValue) Source #
Returns the rightValue if the Either is in a Left state. Returns the Right value if the Either is in a Right state.
Parameters
| param | rightValue | Value to return if in the Left state |
| returns | Returns an unwrapped Right value | |
method Unit IfLeft (Action<L> Left) Source #
Executes the Left action if the Either is in a Left state.
Parameters
| param | Left | Function to generate a Right value if in the Left state |
| returns | Returns an unwrapped Right value | |
method Unit IfRight (Action<R> Right) Source #
Invokes the Right action if the Either is in a Right state, otherwise does nothing
Parameters
| param | Right | Action to invoke |
| returns | Unit | |
method L IfRight (L leftValue) Source #
Returns the leftValue if the Either is in a Right state. Returns the Left value if the Either is in a Left state.
Parameters
| param | leftValue | Value to return if in the Left state |
| returns | Returns an unwrapped Left value | |
method L IfRight (Func<L> Right) Source #
Returns the result of Right() if the Either is in a Right state. Returns the Left value if the Either is in a Left state.
Parameters
| param | Right | Function to generate a Left value if in the Right state |
| returns | Returns an unwrapped Left value | |
method L IfRight (Func<R, L> rightMap) Source #
Returns the result of rightMap if the Either is in a Right state. Returns the Left value if the Either is in a Left state.
Parameters
| param | rightMap | Function to generate a Left value if in the Right state |
| returns | Returns an unwrapped Left value | |
method IEnumerable<R> AsEnumerable () Source #
Singleton enumerable if in a right state, otherwise empty.
method Iterable<R> ToIterable () Source #
Singleton Iterable if in a right state, otherwise empty.
method Lst<R> ToList () Source #
Project the Either into a Lst R
Parameters
| returns | If the Either is in a Right state, a Lst of R with one item. A zero length Lst R otherwise | |
method Arr<R> ToArray () Source #
Project the Either into an ImmutableArray R
Parameters
| returns | If the Either is in a Right state, an immutable-array of R with one item. A zero-length array of R otherwise | |
method Option<R> ToOption () Source #
Convert the Either to an Option
Parameters
| returns | Some(Right) or None | |
method Eff<R> ToEff (Func<L, Error> Left) Source #
Convert to an Eff
Parameters
| param | Left | Map the |
| returns |
| |
method EitherT<L, IO, R> ToIO () Source #
Convert to an Either transformer with embedded IO
Parameters
| returns | ||
method int CompareTo <OrdL, OrdR> (Either<L, R> other) Source #
CompareTo
method bool Equals <EqL, EqR> (Either<L, R> other) Source #
Equality override
method int GetHashCode () Source #
method Res MatchUntyped <Res> (Func<object?, Res> Left, Func<object?, Res> Right) Source #
Match the Right and Left values but as objects. This can be useful to avoid reflection.
method Type GetUnderlyingRightType () Source #
Find out the underlying Right type
method Type GetUnderlyingLeftType () Source #
Find out the underlying Left type
method Type GetUnderlyingType () Source #
method Either<R, L> Swap () Source #
Flips the left and right tagged values
Parameters
| returns | Either with the types swapped | |
method bool ForAll (Func<R, bool> Right) Source #
Invokes a predicate on the value of the Either if it's in the Right state
Parameters
| type | L | Left |
| type | R | Right |
| param | self | Either to forall |
| param | Right | Predicate |
| returns | True if the Either is in a Left state. True if the Either is in a Right state and the predicate returns True. False otherwise. | |
method bool BiForAll (Func<L, bool> Left, Func<R, bool> Right) Source #
Invokes a predicate on the value of the Either if it's in the Right state
Parameters
| type | L | Left |
| type | R | Right |
| param | self | Either to forall |
| param | Right | Predicate |
| param | Left | Predicate |
| returns | True if either Predicate returns true | |
method S Fold <S> (S state, Func<S, R, S> Right) Source #
Either types are like lists of 0 or 1 items, and therefore follow the same rules when folding.
In the case of lists, 'Fold', when applied to a binary operator, a starting value(typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:
Parameters
| type | S | Aggregate state type |
| param | state | Initial state |
| param | Right | Folder function, applied if structure is in a Right state |
| returns | The aggregate state | |
method S BiFold <S> (S state, Func<S, L, S> Left, Func<S, R, S> Right) Source #
Either types are like lists of 0 or 1 items, and therefore follow the same rules when folding.
In the case of lists, 'Fold', when applied to a binary operator, a starting value(typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:
Parameters
| type | S | Aggregate state type |
| param | state | Initial state |
| param | Right | Folder function, applied if Either is in a Right state |
| param | Left | Folder function, applied if Either is in a Left state |
| returns | The aggregate state | |
method bool Exists (Func<R, bool> pred) Source #
Invokes a predicate on the value of the Either if it's in the Right state
Parameters
| type | L | Left |
| type | R | Right |
| param | self | Either to check existence of |
| param | pred | Predicate |
| returns | True if the Either is in a Right state and the predicate returns True. False otherwise. | |
method Either<L, R> Do (Action<R> f) Source #
Impure iteration of the bound values in the structure
Parameters
| returns | Returns the original unmodified structure | |
method K<F, Either<L, B>> Traverse <F, B> (Func<R, K<F, B>> f) Source #
Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.
Parameters
| type | F | Applicative functor trait |
| type | B | Bound value (output) |
| param | f | |
| param | ta | Traversable structure |
method Either<L, B> Map <B> (Func<R, B> f) Source #
Maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | R | Right |
| type | B | Mapped Either type |
| param | f | Map function |
| returns | Mapped Either | |
method Either<B, R> MapLeft <B> (Func<L, B> f) Source #
Maps the value in the Either if it's in a Left state
Parameters
| type | L | Left |
| type | R | Right |
| type | B | Mapped Either type |
| param | f | Map function |
| returns | Mapped Either | |
method Either<L2, R2> BiMap <L2, R2> (Func<L, L2> Left, Func<R, R2> Right) Source #
Bi-maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | R | Right |
| type | LRet | Left return |
| type | RRet | Right return |
| param | Right | Right map function |
| param | Left | Left map function |
| returns | Mapped Either | |
method Either<L, B> Bind <B> (Func<R, Either<L, B>> f) Source #
Monadic bind
Parameters
| type | L | Left |
| type | R | Right |
| type | B | Resulting bound value |
| param | f | Bind function |
| returns | Bound Either | |
method Either<L, B> Bind <B> (Func<R, K<Either<L>, B>> f) Source #
Monadic bind
Parameters
| type | L | Left |
| type | R | Right |
| type | B | |
| param | f | |
| returns | Bound Either | |
method Either<L2, R2> BiBind <L2, R2> (Func<L, Either<L2, R2>> Left, Func<R, Either<L2, R2>> Right) Source #
Bi-bind. Allows mapping of both monad states
method Either<L2, R> BindLeft <L2> (Func<L, Either<L2, R>> f) Source #
Bind left. Binds the left path of the monad only
method Either<L, U> Select <U> (Func<R, U> f) Source #
Maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | TR | Right |
| type | UR | Mapped Either type |
| param | f | Map function |
| returns | Mapped Either | |
method Either<L, T> SelectMany <S, T> (Func<R, Either<L, S>> bind, Func<R, S, T> project) Source #
Monadic bind function
method Either<L, Unit> SelectMany (Func<R, Guard<L, Unit>> f) Source #
Monadic bind function
method Either<L, C> SelectMany <C> (Func<R, Guard<L, Unit>> bind, Func<R, Unit, C> project) Source #
Monadic bind function
method Either<L, B> Bind <B> (Func<R, Pure<B>> f) Source #
Monadic bind
Parameters
| param | f | Bind function |
method Either<L, R> Bind (Func<R, Fail<L>> f) Source #
Monadic bind
Parameters
| param | f | Bind function |
method Either<L, C> SelectMany <B, C> (Func<R, Pure<B>> bind, Func<R, B, C> project) Source #
Monadic bind and project
Parameters
| param | bind | Bind function |
| param | project | Project function |
method Either<L, C> SelectMany <B, C> (Func<R, Fail<L>> bind, Func<R, B, C> _) Source #
Monadic bind and project
Parameters
| param | bind | Bind function |
| param | project | Project function |
method Lst<R> RightToList () Source #
Project the Either into a Lst R
Parameters
| returns | If the Either is in a Right state, a Lst of R with one item. A zero length Lst R otherwise | |
method Arr<R> RightToArray () Source #
Project the Either into an ImmutableArray R
Parameters
| returns | If the Either is in a Right state, a ImmutableArray of R with one item. A zero length ImmutableArray of R otherwise | |
method Seq<R> RightToSeq () Source #
Convert either to sequence of 0 or 1 right values
Operators
operator < (Either<L, R> lhs, Fail<L> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈 rhs | |
operator <= (Either<L, R> lhs, Fail<L> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈 rhs | |
operator > (Either<L, R> lhs, Fail<L> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉rhs | |
operator >= (Either<L, R> lhs, Fail<L> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs >= rhs | |
operator < (Either<L, R> lhs, Pure<R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈 rhs | |
operator <= (Either<L, R> lhs, Pure<R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈= rhs | |
operator > (Either<L, R> lhs, Pure<R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉rhs | |
operator >= (Either<L, R> lhs, Pure<R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉= rhs | |
operator < (Fail<L> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈 rhs | |
operator <= (Fail<L> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈= rhs | |
operator > (Fail<L> lhs, Either<L, R>rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉rhs | |
operator >= (Fail<L> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉= rhs | |
operator < (Pure<R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈 rhs | |
operator <= (Pure<R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈= rhs | |
operator > (Pure<R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉rhs | |
operator >= (Pure<R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉= rhs | |
operator < (Either<L, R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈 rhs | |
operator <= (Either<L, R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs〈= rhs | |
operator > (Either<L, R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉rhs | |
operator >= (Either<L, R> lhs, Either<L, R> rhs) Source #
Comparison operator
Parameters
| param | lhs | The left hand side of the operation |
| param | rhs | The right hand side of the operation |
| returns | True if lhs 〉= rhs | |
struct EitherContext <L, R, Ret> Source #
Context for the fluent Either matching
struct EitherUnitContext <L, R> Source #
Context for the fluent Either matching
record Left (L Value) Source #
Left case type
Parameters
| param | Value | Left value |
Properties
Methods
method B Match <B> (Func<L, B> Left, Func<R, B> Right) Source #
Invokes the Right or Left function depending on the state of the Either
Parameters
| type | B | Return type |
| param | Left | Function to invoke if in a Left state |
| param | Right | Function to invoke if in a Right state |
| returns | The return value of the invoked function | |
method int GetHashCode () Source #
Get a hash code for the structure
method IEnumerable<R> AsEnumerable () Source #
Singleton enumerable if in a right state, otherwise empty enumerable
method int CompareTo <OrdL, OrdR> (Either<L, R> other) Source #
Compare this structure to another to find its relative ordering
method Either<L, B> Map <B> (Func<R, B> f) Source #
Maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | R | Right |
| type | B | Mapped Either type |
| param | f | Map function |
| returns | Mapped Either | |
method Either<L2, R2> BiMap <L2, R2> (Func<L, L2> Left, Func<R, R2> Right) Source #
Bi-maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | R | Right |
| type | L2 | Left return |
| type | R2 | Right return |
| param | Right | Right map function |
| param | Left | Left map function |
| returns | Mapped Either | |
Methods
method Either<L, R> Right <L, R> (R value) Source #
Construct an Either value in a Right state.
Right is often synonymous with 'correct', or 'success', although that isn't a requirement for any reason other
than the default monad bind behaviour. Left shortcuts and 'fails', whereas Right means we can successfully
continue.
Parameters
| type | L | Left value type |
| type | R | Right value type |
| param | value | Value to construct the |
| returns | Constructed | |
method Either<L, R> Left <L, R> (L value) Source #
Construct an Either value in a Left state.
Left is often synonymous with 'failure', or 'error', although that isn't a requirement for any reason other
than the default monad bind behaviour. Left shortcuts and 'fails', whereas Right means we can successfully
continue.
Parameters
| type | L | Left value type |
| type | R | Right value type |
| param | value | Value to construct the |
| returns | Constructed | |
record Right (R Value) Source #
Right case-type
Parameters
| param | Value | Right value |
Properties
Methods
method B Match <B> (Func<L, B> Left, Func<R, B> Right) Source #
Invokes the Right or Left function depending on the state of the Either
Parameters
| type | B | Return type |
| param | Left | Function to invoke if in a Left state |
| param | Right | Function to invoke if in a Right state |
| returns | The return value of the invoked function | |
method int GetHashCode () Source #
Get a hash code for the structure
method IEnumerable<R> AsEnumerable () Source #
Singleton enumerable if in a right state, otherwise empty enumerable
method int CompareTo <OrdL, OrdR> (Either<L, R> other) Source #
Compare this structure to another to find its relative ordering
method Either<L, B> Map <B> (Func<R, B> f) Source #
Maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | R | Right |
| type | B | Mapped Either type |
| param | f | Map function |
| returns | Mapped Either | |
method Either<L2, R2> BiMap <L2, R2> (Func<L, L2> Left, Func<R, R2> Right) Source #
Bi-maps the value in the Either if it's in a Right state
Parameters
| type | L | Left |
| type | R | Right |
| type | L2 | Left return |
| type | R2 | Right return |
| param | Right | Right map function |
| param | Left | Left map function |
| returns | Mapped Either | |