10#if !CSX_EITHER_INTERNAL
26#if !CSX_EITHER_INTERNAL
29 internal abstract class Either<TLeft, TRight>
38#region Basic Match Methods
57#if !CSX_EITHER_INTERNAL
60 internal sealed class Left<TLeft, TRight> :
Either<TLeft, TRight>
71#if !CSX_EITHER_INTERNAL
74 internal sealed class Right<TLeft, TRight> :
Either<TLeft, TRight>
87#if !CSX_EITHER_INTERNAL
90 internal static class Either
99 Func<TRight, TResult> func)
103 if (either.MatchRight(out right))
121 Func<TLeft, TLeft1> mapLeft,
122 Func<TRight, TRight1> mapRight)
126 if (either.MatchRight(out right))
143 if (either.MatchRight(out value))
148 throw new ArgumentException(nameof(either),
string.Format(
"The either value was Left {0}", either));
158 return either.MatchLeft(out value) ? value : @
default;
168 return either.MatchRight(out value) ? value : @
default;
192 return Try(() => (TRight)obj);
195#if !CSX_REM_MAYBE_FUNC
212#region Value Case Constructors
241 throw new Exception(message);
253 if (either.MatchRight(out right))
263#region Linq Operators
269 Func<TRight, TResult> selector)
271 return Map(either, selector);
277 return Bind(result, func);
283#if !CSX_EITHER_INTERNAL
288#region Alternative Match Methods
291 Action<TLeft> ifLeft,
292 Action<TRight> ifRight)
296 if (either.MatchLeft(out left))
314 return Either.Return(value);
320 return Either.Bind(either, func);
324 Func<TRight, TResult> func)
326 return Either.Map(either, func);
330 Func<TLeft, TLeft1> mapLeft,
331 Func<TRight, TRight1> mapRight)
333 return Either.Bimap(either, mapLeft, mapRight);
static Either< TLeft, TResult > Bind< TLeft, TRight, TResult >(this Either< TLeft, TRight > either, Func< TRight, Either< TLeft, TResult > > func)
static Either< string, TRight > ToEither< TRight >(this TRight value)
Equivalent to monadic CSharpx.Either.Return<TRight> operation. Builds a CSharpx.Right<TLeft,...
static void Match< TLeft, TRight >(this Either< TLeft, TRight > either, Action< TLeft > ifLeft, Action< TRight > ifRight)
static bool IsLeft< TLeft, TRight >(this Either< TLeft, TRight > either)
static Either< TLeft, TResult > Map< TLeft, TRight, TResult >(this Either< TLeft, TRight > either, Func< TRight, TResult > func)
static Either< TLeft1, TRight1 > Bimap< TLeft, TRight, TLeft1, TRight1 >(this Either< TLeft, TRight > either, Func< TLeft, TLeft1 > mapLeft, Func< TRight, TRight1 > mapRight)
static bool IsRight< TLeft, TRight >(this Either< TLeft, TRight > either)
static TRight GetOrFail< TLeft, TRight >(Either< TLeft, TRight > either)
Returns a Either Right or fail with an exception.
static Either< TLeft, TRight > Left< TLeft, TRight >(TLeft value)
static Either< TLeft, TResult > Map< TLeft, TRight, TResult >(Either< TLeft, TRight > either, Func< TRight, TResult > func)
Transforms a Either's right value by using a specified mapping function.
bool MatchRight(out TRight value)
static Either< string, TRight > Return< TRight >(TRight value)
Inject a value into the Either type, returning Right case.
static TLeft GetLeft< TLeft, TRight >(this Either< TLeft, TRight > either)
static TRight GetRightOrDefault< TLeft, TRight >(Either< TLeft, TRight > either, TRight @default)
Returns a Either Right or a defualt value.
static Either< TLeft1, TRight1 > Bimap< TLeft, TRight, TLeft1, TRight1 >(Either< TLeft, TRight > either, Func< TLeft, TLeft1 > mapLeft, Func< TRight, TRight1 > mapRight)
Maps both parts of a Either type. Applies the first function if Either is Left. Otherwise applies the...
static TLeft GetLeftOrDefault< TLeft, TRight >(Either< TLeft, TRight > either, TLeft @default)
Returns a Either Left or a defualt value.
static Either< TLeft, TResult > Select< TLeft, TRight, TResult >(this Either< TLeft, TRight > either, Func< TRight, TResult > selector)
Map operation compatible with Linq.
static Either< TLeft, TRight > Right< TLeft, TRight >(TRight value)
static Either< Exception, TRight > Try< TRight >(Func< TRight > func)
Wraps a function, encapsulates any exception thrown within to a Either.
bool MatchLeft(out TLeft value)
static Either< TLeft, TResult > SelectMany< TLeft, TRight, TResult >(this Either< TLeft, TRight > result, Func< TRight, Either< TLeft, TResult > > func)
static Either< Exception, TRight > Cast< TRight >(object obj)
Attempts to cast an object. Stores the cast value in 1Of2 if successful, otherwise stores the excepti...
static Either< string, TRight > Fail< TRight >(string message)
Fail with a message. Not part of mathematical definition of a monad.
static Either< TLeft, TRight > FromMaybe< TLeft, TRight >(Maybe< TRight > maybe, TLeft left)
static Either< TLeft, TResult > Bind< TLeft, TRight, TResult >(Either< TLeft, TRight > either, Func< TRight, Either< TLeft, TResult > > func)
Monadic bind.
Models a CSharpx.Maybe when contains a value.
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
MaybeType Tag
Type discriminator.
MaybeType
Discriminator for CSharpx.Maybe.