18 public struct Either<
A,
B> : IEquatable<Either<A, B>>, IComparable, IComparable<Either<A, B>> {
23 public readonly
bool isA;
34 private readonly
A _a;
35 private readonly
B _b;
70 throw new ArgumentNullException(
"Cannot initialize an Either with a null value.");
83 throw new ArgumentNullException(
"Cannot initialize an Either with a null value.");
95 public void Match(Action<A> ifA, Action<B> ifB) {
97 if (ifA !=
null) ifA(_a);
99 if (ifB !=
null) ifB(_b);
123 return _a.GetHashCode();
125 return _b.GetHashCode();
129 public override bool Equals(
object obj) {
141 return _a.Equals(other._a);
143 return _b.Equals(other._b);
149 throw new ArgumentException();
159 IComparable<A> ca = _a as IComparable<A>;
161 return ca.CompareTo(other._a);
163 IComparable c = _a as IComparable;
165 return c.CompareTo(other._b);
171 IComparable<B> cb = _b as IComparable<B>;
173 return cb.CompareTo(other._b);
175 IComparable c = _b as IComparable;
177 return c.CompareTo(other._b);
186 return either0.
Equals(either1);
190 return !either0.
Equals(either1);
A struct that represents a value that could or could not exist. Unlike the built-int nullable types,...
static readonly NoneType None
static Maybe< T > Some(T t)
Constructs a Maybe given a specific value. This value needs to always be non-null if the type is a re...
A data structure that represents either a value of type A or a value of type B. The value can never b...
override int GetHashCode()
int CompareTo(object obj)
static bool operator!=(Either< A, B > either0, Either< A, B > either1)
bool TryGetB(out B b)
If this either contains the value of B, the out argument is filled with that value and this method re...
readonly bool isA
Returns whether or not this Either contains the first value.
Either(B b)
Constructs an Either with a value of B.
void Match(Action< A > ifA, Action< B > ifB)
Calls the first delegate with the value of A if it is present, else calls the second delegate with th...
bool isB
Returns whether or not this Either contains the second value.
bool TryGetA(out A a)
If this either contains the value of A, the out argument is filled with that value and this method re...
static bool operator>=(Either< A, B > either0, Either< A, B > either1)
static bool operator>(Either< A, B > either0, Either< A, B > either1)
static bool operator<=(Either< A, B > either0, Either< A, B > either1)
int CompareTo(Either< A, B > other)
Maybe< B > b
Returns a Maybe that contains the value of B if it exists, or no value if it doesn't.
override bool Equals(object obj)
static bool operator<(Either< A, B > either0, Either< A, B > either1)
static bool operator==(Either< A, B > either0, Either< A, B > either1)
Maybe< A > a
Returns a Maybe that contains the value of A if it exists, or no value if it doesn't.
bool Equals(Either< A, B > other)
Either(A a)
Constructs an Either with a value of A.