Enhanced C#
Language of your choice: library documentation
Public fields | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Either< L, R > Struct Template Reference

Holds a single value of one of two types (L or R). More...


Source file:
Inheritance diagram for Loyc.Either< L, R >:
Loyc.IEither< L, R > Loyc.IHasValue< object >

Remarks

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
 
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...
 

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< L, R >
IMaybe< L > Left [get]
 
IMaybe< R > Right [get]
 
- Properties inherited from Loyc.IHasValue< object >
Value [get]
 

Member Function Documentation

◆ From< L2, R2 >()

static Either<L, R> Loyc.Either< L, R >.From< L2, R2 > ( Either< L2, R2 >  x)
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.

Type Constraints
L2 :L 
R2 :R 
R2 :new 
R2 :Either 
R2 :L 
R2 :R 
R2 :x._hasLeft 
R2 :x._left 
R2 :x._right 

◆ NewLeft()

static Either<L, R> Loyc.Either< L, R >.NewLeft ( value)
static

Simply calls the constructor. This method exists to make it possible to construct an Either when both types are the same.

◆ NewRight()

static Either<L, R> Loyc.Either< L, R >.NewRight ( value)
static

Simply calls the constructor. This method exists to make it possible to construct an Either when both types are the same.

◆ Select< L2, R2 >()

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.