|
Enhanced C#
Loyc library documentation
|
Holds a single value of one of two types (L or R). More...
Holds a single value of one of two types (L or R).
For efficiency, this is a struct, but this makes it possible to default-construct it. In that case its value will be default(R).
Public fields | |
| Maybe< L > | Left => _hasLeft ? _left : new Maybe<L>() |
| Maybe< R > | Right => _hasLeft ? new Maybe<R>() : _right |
| object | Value => _hasLeft ? (object?)_left : _right |
| int ITuple. | Length => 2 |
| object | this[int index] |
| IMaybe< L > IEither< L, R >. | Left => Left |
| IMaybe< R > IEither< L, R >. | Right => Right |
Public Member Functions | |
| static Either< L, R > | R (value) |
| static Either< L, R > | R (value) |
| Either (L value) | |
| Either (R value) | |
| Either< L2, R2 > | Select< L2, R2 > (Func< L, L2 > selectL, Func< R, R2 > selectR) |
| Converts an Either to another with different types. More... | |
| Either< L2, R2 > R2(selectL(_left)) Either< L2, R > | MapLeft< L2 > (Func< L, L2 > selectL) |
Transforms Left with the given selector, if Left.HasValue. Otherwise, returns Right unchanged. More... | |
| Either< L2, R2 > R2(selectL(_left)) Either< L2, R > R(selectL(_left)) Either< L, R2 > | MapRight< R2 > (Func< R, R2 > selectR) |
Transforms Right with the given selector, if Right.HasValue. Otherwise, returns Left unchanged. More... | |
| Either< L2, R2 > R2(selectL(_left)) Either< L2, R > R(selectL(_left)) Either< L, R2 > R2(selectR(_right)) T | Match< T > (Func< L, T > selectL, Func< R, T > selectR) |
Transforms Left or Right with exactly one of the two functions given, returning whatever that function returns. More... | |
| Either< L, R > | IfLeft (Action< L > actionL) |
Runs actionL if Left.HasValue. Equivalent to Left.Then(actionL), but also returns this. More... | |
| Either< L, R > | IfRight (Action< R > actionR) |
Runs actionR if Right.HasValue. Equivalent to Right.Then(actionL), but also returns this. More... | |
| override string | ToString () |
| override int | GetHashCode () |
| override bool | Equals (object?obj) |
| bool | Equals (ITuple?other) |
| bool | Equals (Either< L, R > other) |
Static Public Member Functions | |
| static Either< L, R > | NewLeft (L value) |
| Simply calls the constructor. This method exists to make it possible to construct an Either when both types are the same. More... | |
| static Either< L, R > | NewRight (R value) |
| Simply calls the constructor. This method exists to make it possible to construct an Either when both types are the same. More... | |
| static implicit | operator Either< L, R > (L value) |
| static implicit | operator Either< L, R > (R value) |
| static Either< L, R > | From< L2, R2 > (Either< L2, R2 > x) |
| Does an upcast, e.g. Either{string,ArgumentException} to Either{object,Exception}. C# does not allow defining conversion operators to take generic parameters, so you'll have to put up with this hassle instead. More... | |
Additional Inherited Members | |
Properties inherited from Loyc.IEither< out L, out R > | |
| IMaybe< L > | Left [get] |
| IMaybe< R > | Right [get] |
Properties inherited from Loyc.IValue< out T > | |
| T | Value [get] |
|
static |
Does an upcast, e.g. Either{string,ArgumentException} to Either{object,Exception}. C# does not allow defining conversion operators to take generic parameters, so you'll have to put up with this hassle instead.
Sadly, automatically upcasting value types to reference types doesn't seem possible.
| L2 | : | L | |
| R2 | : | R | |
| R2 | : | new | |
| R2 | : | Either | |
| R2 | : | L | |
| R2 | : | R | |
| R2 | : | x._hasLeft | |
| R2 | : | x._left | |
| R2 | : | x._right |
|
inline |
Runs actionL if Left.HasValue. Equivalent to Left.Then(actionL), but also returns this.
|
inline |
Runs actionR if Right.HasValue. Equivalent to Right.Then(actionL), but also returns this.
| Either<L2, R2> R2 (selectL(_left)) Either<L2, R> Loyc.Either< L, R >.MapLeft< L2 > | ( | Func< L, L2 > | selectL | ) |
Transforms Left with the given selector, if Left.HasValue. Otherwise, returns Right unchanged.
| Either<L2, R2> R2 (selectL(_left)) Either<L2, R> R (selectL(_left)) Either<L, R2> Loyc.Either< L, R >.MapRight< R2 > | ( | Func< R, R2 > | selectR | ) |
Transforms Right with the given selector, if Right.HasValue. Otherwise, returns Left unchanged.
| Either<L2, R2> R2 (selectL(_left)) Either<L2, R> R (selectL(_left)) Either<L, R2> R2 (selectR(_right)) T Loyc.Either< L, R >.Match< T > | ( | Func< L, T > | selectL, |
| Func< R, T > | selectR | ||
| ) |
Transforms Left or Right with exactly one of the two functions given, returning whatever that function returns.
|
static |
Simply calls the constructor. This method exists to make it possible to construct an Either when both types are the same.
|
static |
Simply calls the constructor. This method exists to make it possible to construct an Either when both types are the same.
| Either<L2, R2> Loyc.Either< L, R >.Select< L2, R2 > | ( | Func< L, L2 > | selectL, |
| Func< R, R2 > | selectR | ||
| ) |
Converts an Either to another with different types.
| object Loyc.Either< L, R >.this[int index] |
1.8.7