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.
- Either <L, R>
- IsRight
- IsLeft
- 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)
- Right (Action<R> right)
- Right <Ret> (Func<R, Ret> right)
- CompareTo (object? obj)
- GetEnumerator ()
- LeftSpan ()
- RightSpan ()
- LeftToList ()
- LeftToArray ()
- ToList ()
- ToArray ()
- ToSeq ()
- LeftToSeq ()
- ToOption ()
- ToStream <M> ()
- LeftToStream <M> ()
- 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)
- | (Either<L, R> lhs, Either<L, R> rhs)
- | (K<Either<L>, R> lhs, Either<L, R> rhs)
- | (Either<L, R> lhs, K<Either<L>, R> rhs)
- | (Either<L, R> ma, Pure<R> mb)
- | (Either<L, R> ma, Fail<L> mb)
- | (Either<L, R> ma, CatchM<L, Either<L>, R> mb)
- 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)
- Equals (Fail<L> other)
- Equals (Pure<R> other)
- MatchUntyped <Res> (Func<object?, Res> Left, Func<object?, Res> Right)
- GetUnderlyingRightType ()
- GetUnderlyingLeftType ()
- Right (R value)
- Left (L value)
- 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 <B> (Func<L, Either<B, R>> f)
- Select <U> (Func<R, U> f)
- SelectMany <S, T> (Func<R, Either<L, S>> bind, Func<R, S, T> 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>
- EitherExtensions
- As <L, R> (this K<Either<L>, R> ma)
- Flatten <L, R> (this K<Either<L>, Either<L, R>> ma)
- Flatten <L, R> (this K<Either<L>, K<Either<L>, R>> ma)
- Lefts <L, R> (this IEnumerable<Either<L, R>> self)
- Lefts <L, R> (this Seq<Either<L, R>> self)
- Rights <L, R> (this IEnumerable<Either<L, R>> self)
- Rights <L, R> (this Seq<Either<L, R>> self)
- Partition <L, R> (this IEnumerable<Either<L, R>> self)
- Partition <L, R> (this Seq<Either<L, R>> self)
- ToValidation <L, R> (this Either<L, R> ma)
- ToEff <R> (this Either<Error, R> ma)
- ToEff <R> (this Either<Exception, R> ma)
- ToEff <R> (this Either<string, R> ma)
- EitherExtensions
- Map <L, A, B> (this Func<A, B> f, K<Either<L>, A> ma)
- Map <L, A, B> (this Func<A, B> f, Either<L, A> ma)
- Action <L, A, B> (this Either<L, A> ma, K<Either<L>, B> mb)
- Action <L, A, B> (this K<Either<L>, A> ma, K<Either<L>, B> mb)
- Apply <L, A, B> (this Either<L, Func<A, B>> mf, K<Either<L>, A> ma)
- Apply <L, A, B> (this K<Either<L>, Func<A, B>> mf, K<Either<L>, A> ma)
- EitherGuardExtensions
- SelectMany <L, A> (this Either<L, A> ma, Func<A, Guard<L, Unit>> f)
- SelectMany <L, A, C> (this Either<L, A> ma, Func<A, Guard<L, Unit>> bind, Func<A, Unit, C> project)
- Left <L, R> (L Value)
- IsRight
- IsLeft
- Match <B> (Func<L, B> Left, Func<R, B> Right)
- ToString ()
- GetHashCode ()
- LeftSpan ()
- RightSpan ()
- 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
- Prelude
- Right <L, R> (R value)
- Right <R> (R value)
- Left <L, R> (L value)
- Left <L> (L value)
- flatten <L, R> (Either<L, Either<L, R>> ma)
- plus <NUM, L, R> (Either<L, R> x, Either<L, R> y)
- subtract <NUM, L, R> (Either<L, R> x, Either<L, R> y)
- product <NUM, L, R> (Either<L, R> x, Either<L, R> y)
- divide <NUM, L, R> (Either<L, R> x, Either<L, R> y)
- isRight <L, R> (Either<L, R> value)
- isLeft <L, R> (Either<L, R> value)
- ifLeft <L, R> (Either<L, R> either, Func<R> Left)
- ifLeft <L, R> (Either<L, R> either, Func<L, R> leftMap)
- ifLeft <L, R> (Either<L, R> either, R rightValue)
- ifLeft <L, R> (Either<L, R> either, Action<L> Left)
- ifRight <L, R> (Either<L, R> either, Action<R> Right)
- ifRight <L, R> (Either<L, R> either, L leftValue)
- ifRight <L, R> (Either<L, R> either, Func<L> Left)
- ifRight <L, R> (Either<L, R> either, Func<R, L> leftMap)
- match <L, R, Ret> (Either<L, R> either, Func<L, Ret> Left, Func<R, Ret> Right)
- match <L, R> (Either<L, R> either, Action<L> Left, Action<R> Right)
- bifold <L, R, S> (Either<L, R> either, S state, Func<S, L, S> Left, Func<S, R, S> Right)
- forall <L, R> (Either<L, R> either, Func<R, bool> pred)
- biforall <L, R> (Either<L, R> either, Func<L, bool> Left, Func<R, bool> Right)
- count <L, R> (Either<L, R> either)
- exists <L, R> (Either<L, R> either, Func<R, bool> pred)
- map <L, R, Ret> (Either<L, R> either, Func<R, Ret> mapper)
- bimap <L, R, LRet, RRet> (Either<L, R> either, Func<L, LRet> Left, Func<R, RRet> Right)
- bind <L, R, Ret> (Either<L, R> either, Func<R, Either<L, Ret>> binder)
- Match <L, R, Ret> ( this IEnumerable<Either<L, R>> list, Func<R, Ret> Right, Func<L, Ret> Left)
- match <L, R, Ret> ( IEnumerable<Either<L, R>> list, Func<R, Ret> Right, Func<L, Ret> Left)
- rightToList <L, R> (Either<L, R> either)
- rightToArray <L, R> (Either<L, R> either)
- leftToList <L, R> (Either<L, R> either)
- leftToArray <L, R> (Either<L, R> either)
- lefts <L, R> (IEnumerable<Either<L, R>> self)
- lefts <L, R> (Seq<Either<L, R>> self)
- rights <L, R> (IEnumerable<Either<L, R>> self)
- rights <L, R> (Seq<Either<L, R>> self)
- partition <L, R> (IEnumerable<Either<L, R>> self)
- partition <L, R> (Seq<Either<L, R>> self)
- Prelude
- map <L, A, B> (Func<A, B> f, K<Either<L>, A> ma)
- action <L, A, B> (K<Either<L>, A> ma, K<Either<L>, B> mb)
- apply <L, A, B> (K<Either<L>, Func<A, B>> mf, K<Either<L>, A> ma)
- Right <L, R> (R Value)
- IsRight
- IsLeft
- Match <B> (Func<L, B> Left, Func<R, B> Right)
- ToString ()
- GetHashCode ()
- LeftSpan ()
- RightSpan ()
- 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
- Either <L>
- IEither
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
.
type | L | Left |
type | R | Right |
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
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
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.
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.
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.
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.
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
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.
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.
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.
param | rightMap | Function to generate a Left value if in the Right state |
returns | Returns an unwrapped Left value |
method EitherUnitContext<L, R> Right (Action<R> right) Source #
Match Right and return a context. You must follow this with .Left(...) to complete the match
param | right | Action to invoke if the Either is in a Right state |
returns | Context that must have Left() called upon it. |
method EitherContext<L, R, Ret> Right <Ret> (Func<R, Ret> right) Source #
Match Right and return a context. You must follow this with .Left(...) to complete the match
param | right | Action to invoke if the Either is in a Right state |
returns | Context that must have Left() called upon it. |
method IEnumerator<R> GetEnumerator () Source #
method Lst<L> LeftToList () Source #
Project the Either into a Lst L
returns | If the Either is in a Left state, a Lst of L with one item. A zero length Lst L otherwise |
method Arr<L> LeftToArray () Source #
Project the Either into an ImmutableArray L
returns | If the Either is in a Left state, a ImmutableArray of L with one item. A zero length ImmutableArray of L otherwise |
method Lst<R> ToList () Source #
Project the Either into a Lst R
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
returns | If the Either is in a Right state, a ImmutableArray of R with one item. A zero length ImmutableArray of R otherwise |
method Eff<R> ToEff (Func<L, Error> Left) Source #
Convert to an Eff
param | Left | Map the |
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 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
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
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
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:
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:
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
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
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.
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
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
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
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
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
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<B, R> BindLeft <B> (Func<L, Either<B, 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
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
returns | Bound Either |
method Either<L, C> SelectMany <B, C> (Func<R, Pure<B>> bind, Func<R, B, C> project) Source #
Monadic bind and project
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
param | bind | Bind function |
param | project | Project function |
method Lst<R> RightToList () Source #
Project the Either into a Lst R
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
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
operator < (Either<L, R> lhs, Fail<L> rhs) Source #
Comparison operator
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
class EitherExtensions Source #
Extension methods for Either
method IEnumerable<L> Lefts <L, R> (this IEnumerable<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Left' elements. All the 'Left' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method Seq<L> Lefts <L, R> (this Seq<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Left' elements. All the 'Left' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method IEnumerable<R> Rights <L, R> (this IEnumerable<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Right' elements. All the 'Right' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method Seq<R> Rights <L, R> (this Seq<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Right' elements. All the 'Right' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method (IEnumerable<L> Lefts, IEnumerable<R> Rights) Partition <L, R> (this IEnumerable<Either<L, R>> self) Source #
Partitions a list of 'Either' into two lists. All the 'Left' elements are extracted, in order, to the first component of the output. Similarly the 'Right' elements are extracted to the second component of the output.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | A tuple containing the an enumerable of L and an enumerable of R |
method (Seq<L> Lefts, Seq<R> Rights) Partition <L, R> (this Seq<Either<L, R>> self) Source #
Partitions a list of 'Either' into two lists. All the 'Left' elements are extracted, in order, to the first component of the output. Similarly the 'Right' elements are extracted to the second component of the output.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | A tuple containing the an enumerable of L and an enumerable of R |
class EitherExtensions Source #
method Either<L, B> Map <L, A, B> (this Func<A, B> f, K<Either<L>, A> ma) Source #
Functor map operation
Unwraps the value within the functor, passes it to the map function f
provided, and
then takes the mapped value and wraps it back up into a new functor.
param | ma | Functor to map |
param | f | Mapping function |
returns | Mapped functor |
method Either<L, B> Map <L, A, B> (this Func<A, B> f, Either<L, A> ma) Source #
Functor map operation
Unwraps the value within the functor, passes it to the map function f
provided, and
then takes the mapped value and wraps it back up into a new functor.
param | ma | Functor to map |
param | f | Mapping function |
returns | Mapped functor |
method Either<L, B> Action <L, A, B> (this Either<L, A> ma, K<Either<L>, B> mb) Source #
Applicative action: runs the first applicative, ignores the result, and returns the second applicative
method Either<L, B> Action <L, A, B> (this K<Either<L>, A> ma, K<Either<L>, B> mb) Source #
Applicative action: runs the first applicative, ignores the result, and returns the second applicative
method Either<L, B> Apply <L, A, B> (this Either<L, Func<A, B>> mf, K<Either<L>, A> ma) Source #
Applicative functor apply operation
Unwraps the value within the ma
applicative-functor, passes it to the unwrapped function(s) within mf
, and
then takes the resulting value and wraps it back up into a new applicative-functor.
param | ma | Value(s) applicative functor |
param | mf | Mapping function(s) |
returns | Mapped applicative functor |
method Either<L, B> Apply <L, A, B> (this K<Either<L>, Func<A, B>> mf, K<Either<L>, A> ma) Source #
Applicative functor apply operation
Unwraps the value within the ma
applicative-functor, passes it to the unwrapped function(s) within mf
, and
then takes the resulting value and wraps it back up into a new applicative-functor.
param | ma | Value(s) applicative functor |
param | mf | Mapping function(s) |
returns | Mapped applicative functor |
class EitherGuardExtensions Source #
method Either<L, Unit> SelectMany <L, A> (this Either<L, A> ma, Func<A, Guard<L, Unit>> f) Source #
method Either<L, C> SelectMany <L, A, C> (this Either<L, A> ma, Func<A, Guard<L, Unit>> bind, Func<A, Unit, C> project) Source #
record Left <L, R> (L Value) Source #
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
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 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
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
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 |
method Either<L, R> Right <L, R> (R value) Source #
Either constructor Constructs an Either in a Right state
type | L | Left |
type | R | Right |
param | value | Right value |
returns | A new Either instance |
method Pure<R> Right <R> (R value) Source #
Constructs an EitherRight which can be implicitly cast to an Either<_, R>
type | R | Right |
param | value | Right value |
returns | A new EitherRight instance |
method Either<L, R> Left <L, R> (L value) Source #
Either constructor Constructs an Either in a Left state
type | L | Left |
type | R | Right |
param | value | Left value |
returns | A new Either instance |
method Fail<L> Left <L> (L value) Source #
Constructs an EitherLeft which can be implicitly cast to an Either<L, _>
type | L | Left |
param | value | Right value |
returns | A new EitherLeft instance |
method Either<L, R> plus <NUM, L, R> (Either<L, R> x, Either<L, R> y) Source #
Add the bound values of x and y, uses an Add trait to provide the add operation for type A. For example x.Add<TInteger,int>(y)
type | NUM | Num of A |
type | A | Bound value type |
param | x | Left hand side of the operation |
param | y | Right hand side of the operation |
returns | An option with y added to x |
method Either<L, R> subtract <NUM, L, R> (Either<L, R> x, Either<L, R> y) Source #
Find the subtract between the two bound values of x and y, uses a Subtract trait to provide the subtract operation for type A. For example x.Subtract<TInteger,int>(y)
type | NUM | Num of A |
type | A | Bound value type |
param | x | Left hand side of the operation |
param | y | Right hand side of the operation |
returns | An option with the subtract between x and y |
method Either<L, R> product <NUM, L, R> (Either<L, R> x, Either<L, R> y) Source #
Find the product between the two bound values of x and y, uses a Product trait to provide the product operation for type A. For example x.Product<TInteger,int>(y)
type | NUM | Num of A |
type | A | Bound value type |
param | x | Left hand side of the operation |
param | y | Right hand side of the operation |
returns | An option with the product of x and y |
method Either<L, R> divide <NUM, L, R> (Either<L, R> x, Either<L, R> y) Source #
Divide the two bound values of x and y, uses a Divide trait to provide the divide operation for type A. For example x.Divide<TDouble,double>(y)
type | NUM | Num of A |
type | A | Bound value type |
param | x | Left hand side of the operation |
param | y | Right hand side of the operation |
returns | An option x / y |
method bool isRight <L, R> (Either<L, R> value) Source #
Returns the state of the Either provided
type | L | Left |
type | R | Right |
param | value | Either to check |
returns | True if the Either is in a Right state |
method bool isLeft <L, R> (Either<L, R> value) Source #
Returns the state of the Either provided
type | L | Left |
type | R | Right |
param | value | Either to check |
returns | True if the Either is in a Left state |
method R ifLeft <L, R> (Either<L, R> either, 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.
param | Left | Function to generate a Right value if in the Left state |
returns | Returns an unwrapped Right value |
method R ifLeft <L, R> (Either<L, R> either, 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.
param | leftMap | Function to generate a Right value if in the Left state |
returns | Returns an unwrapped Right value |
method R ifLeft <L, R> (Either<L, R> either, 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.
param | rightValue | Value to return if in the Left state |
returns | Returns an unwrapped Right value |
method Unit ifLeft <L, R> (Either<L, R> either, Action<L> Left) Source #
Executes the Left action if the Either is in a Left state.
param | Left | Function to generate a Right value if in the Left state |
returns | Returns an unwrapped Right value |
method Unit ifRight <L, R> (Either<L, R> either, Action<R> Right) Source #
Invokes the Right action if the Either is in a Right state, otherwise does nothing
param | Right | Action to invoke |
returns | Unit |
method L ifRight <L, R> (Either<L, R> either, 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.
param | leftValue | Value to return if in the Left state |
returns | Returns an unwrapped Left value |
method L ifRight <L, R> (Either<L, R> either, Func<L> Left) Source #
Returns the result of Left() if the Either is in a Right state. Returns the Left value if the Either is in a Left state.
param | Left | Function to generate a Left value if in the Right state |
returns | Returns an unwrapped Left value |
method L ifRight <L, R> (Either<L, R> either, Func<R, L> leftMap) Source #
Returns the result of leftMap if the Either is in a Right state. Returns the Left value if the Either is in a Left state.
param | leftMap | Function to generate a Left value if in the Right state |
returns | Returns an unwrapped Left value |
method Ret match <L, R, Ret> (Either<L, R> either, Func<L, Ret> Left, Func<R, Ret> Right) Source #
Invokes the Right or Left function depending on the state of the Either provided
type | L | Left |
type | R | Right |
type | Ret | Return type |
param | either | Either to match |
param | Right | Function to invoke if in a Right state |
param | Left | Function to invoke if in a Left state |
returns | The return value of the invoked function |
method Unit match <L, R> (Either<L, R> either, Action<L> Left, Action<R> Right) Source #
Invokes the Right or Left action depending on the state of the Either provided
type | L | Left |
type | R | Right |
param | either | Either to match |
param | Right | Action to invoke if in a Right state |
param | Left | Action to invoke if in a Left state |
returns | Unit |
method S bifold <L, R, S> (Either<L, R> either, 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:
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 forall <L, R> (Either<L, R> either, Func<R, bool> pred) Source #
Invokes a predicate on the value of the Either if it's in the Right state
type | L | Left |
type | R | Right |
param | either | Either to forall |
param | pred | 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 <L, R> (Either<L, R> either, 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
type | L | Left |
type | R | Right |
param | self | Either to forall |
param | Right | Right predicate |
param | Left | Left predicate |
returns | True if the predicate returns True. True if the Either is in a bottom state. |
method int count <L, R> (Either<L, R> either) Source #
Counts the Either
type | L | Left |
type | R | Right |
param | either | Either to count |
returns | 1 if the Either is in a Right state, 0 otherwise. |
method bool exists <L, R> (Either<L, R> either, Func<R, bool> pred) Source #
Invokes a predicate on the value of the Either if it's in the Right state
type | L | Left |
type | R | Right |
param | either | 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, Ret> map <L, R, Ret> (Either<L, R> either, Func<R, Ret> mapper) Source #
Maps the value in the Either if it's in a Right state
type | L | Left |
type | R | Right |
type | Ret | Mapped Either type |
param | either | Either to map |
param | mapper | Map function |
returns | Mapped Either |
method Either<LRet, RRet> bimap <L, R, LRet, RRet> (Either<L, R> either, Func<L, LRet> Left, Func<R, RRet> Right) Source #
Bi-maps the value in the Either if it's in a Right state
type | L | Left |
type | R | Right |
type | LRet | Left return |
type | RRet | Right return |
param | self | Either to map |
param | Right | Right map function |
param | Left | Left map function |
returns | Mapped Either |
method Either<L, Ret> bind <L, R, Ret> (Either<L, R> either, Func<R, Either<L, Ret>> binder) Source #
Monadic bind function https://en.wikipedia.org/wiki/Monad_(functional_programming)
type | L | Left |
type | R | Right |
type | Ret | |
param | either | |
param | binder | |
returns | Bound Either |
method Iterable<Ret> Match <L, R, Ret> ( this IEnumerable<Either<L, R>> list, Func<R, Ret> Right, Func<L, Ret> Left) Source #
Match over a sequence of Eithers
type | L | Left |
type | R | Right |
type | Ret | Mapped type |
param | list | Sequence to match over |
param | Right | Right match function |
param | Left | Left match function |
returns | Sequence of mapped values |
method Iterable<Ret> match <L, R, Ret> ( IEnumerable<Either<L, R>> list, Func<R, Ret> Right, Func<L, Ret> Left) Source #
Match over a sequence of Eithers
type | L | Left |
type | R | Right |
type | Ret | Mapped type |
param | list | Sequence to match over |
param | Right | Right match function |
param | Left | Left match function |
returns | Sequence of mapped values |
method Lst<R> rightToList <L, R> (Either<L, R> either) Source #
Project the Either into a Lst R
type | L | Left |
type | R | Right |
param | either | Either to project |
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 <L, R> (Either<L, R> either) Source #
Project the Either into an ImmutableArray R
type | L | Left |
type | R | Right |
param | either | Either to project |
returns | If the Either is in a Right state, a ImmutableArray of R with one item. A zero length ImmutableArray of R otherwise |
method Lst<L> leftToList <L, R> (Either<L, R> either) Source #
Project the Either into a Lst L
type | L | Left |
type | R | Right |
param | either | Either to project |
returns | If the Either is in a Left state, a Lst of L with one item. A zero length Lst L otherwise |
method Arr<L> leftToArray <L, R> (Either<L, R> either) Source #
Project the Either into an array of L
type | L | Left |
type | R | Right |
param | either | Either to project |
returns | If the Either is in a Right state, an array of L with one item. A zero length array of L otherwise |
method Iterable<L> lefts <L, R> (IEnumerable<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Left' elements. All the 'Left' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method Seq<L> lefts <L, R> (Seq<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Left' elements. All the 'Left' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method Iterable<R> rights <L, R> (IEnumerable<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Right' elements. All the 'Right' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method Seq<R> rights <L, R> (Seq<Either<L, R>> self) Source #
Extracts from a list of 'Either' all the 'Right' elements. All the 'Right' elements are extracted in order.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | An enumerable of L |
method (Iterable<L> Lefts, Iterable<R> Rights) partition <L, R> (IEnumerable<Either<L, R>> self) Source #
Partitions a list of 'Either' into two lists. All the 'Left' elements are extracted, in order, to the first component of the output. Similarly, the 'Right' elements are extracted to the second component of the output.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | A tuple containing the iterables of L and of R |
method (Seq<L> Lefts, Seq<R> Rights) partition <L, R> (Seq<Either<L, R>> self) Source #
Partitions a list of 'Either' into two lists. All the 'Left' elements are extracted, in order, to the first component of the output. Similarly, the 'Right' elements are extracted to the second component of the output.
type | L | Left |
type | R | Right |
param | self | Either list |
returns | A tuple containing the iterables of L and R |
method Either<L, B> map <L, A, B> (Func<A, B> f, K<Either<L>, A> ma) Source #
Functor map operation
Unwraps the value within the functor, passes it to the map function f
provided, and
then takes the mapped value and wraps it back up into a new functor.
param | ma | Functor to map |
param | f | Mapping function |
returns | Mapped functor |
method Either<L, B> action <L, A, B> (K<Either<L>, A> ma, K<Either<L>, B> mb) Source #
Applicative action: runs the first applicative, ignores the result, and returns the second applicative
method Either<L, B> apply <L, A, B> (K<Either<L>, Func<A, B>> mf, K<Either<L>, A> ma) Source #
Applicative functor apply operation
Unwraps the value within the ma
applicative-functor, passes it to the unwrapped function(s) within mf
, and
then takes the resulting value and wraps it back up into a new applicative-functor.
param | ma | Value(s) applicative functor |
param | mf | Mapping function(s) |
returns | Mapped applicative functor |
record Right <L, R> (R Value) Source #
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
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 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
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
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 |