Class Either<TA, TB>
Represents a value of one of two possible types (a disjoint union). An instance of Either is either a Left or a Right.
Inherited Members
Namespace: Akka.Util
Assembly: Akka.dll
Syntax
public abstract class Either<TA, TB>
Type Parameters
Name | Description |
---|---|
TA | The type of the value if this is a Left instance. |
TB | The type of the value if this is a Right instance. |
Constructors
| Edit this page View SourceEither(TA, TB)
Initializes a new instance of the Either<TA, TB> class.
Declaration
protected Either(TA left, TB right)
Parameters
Type | Name | Description |
---|---|---|
TA | left | The left value. |
TB | right | The right value. |
Properties
| Edit this page View SourceIsLeft
Gets a value indicating whether this instance represents a Left.
Declaration
public abstract bool IsLeft { get; }
Property Value
Type | Description |
---|---|
bool |
IsRight
Gets a value indicating whether this instance represents a Right.
Declaration
public abstract bool IsRight { get; }
Property Value
Type | Description |
---|---|
bool |
Left
Gets the left value.
Declaration
protected TA Left { get; }
Property Value
Type | Description |
---|---|
TA |
Right
Gets the right value.
Declaration
protected TB Right { get; }
Property Value
Type | Description |
---|---|
TB |
Value
Gets the contained value, either Left or Right.
Declaration
public object Value { get; }
Property Value
Type | Description |
---|---|
object |
Methods
| Edit this page View SourceFold<TRes>(Func<TA, TRes>, Func<TB, TRes>)
Applies one of the provided functions depending on whether this is a Left or Right.
Declaration
public TRes Fold<TRes>(Func<TA, TRes> left, Func<TB, TRes> right)
Parameters
Type | Name | Description |
---|---|---|
Func<TA, TRes> | left | The function to apply if this is a Left. |
Func<TB, TRes> | right | The function to apply if this is a Right. |
Returns
Type | Description |
---|---|
TRes | The result of applying the corresponding function. |
Type Parameters
Name | Description |
---|---|
TRes | The type of the result. |
MapLeft<TRes>(Func<TA, TRes>)
Maps the left value contained in this Either instance.
Declaration
public Either<TRes, TB> MapLeft<TRes>(Func<TA, TRes> map)
Parameters
Type | Name | Description |
---|---|---|
Func<TA, TRes> | map | The function to apply to the left value if this is a Left. |
Returns
Type | Description |
---|---|
Either<TRes, TB> | A new Either instance with the transformed left value. |
Type Parameters
Name | Description |
---|---|
TRes | The type of the transformed left value. |
MapRight<TRes>(Func<TB, TRes>)
Maps the right value contained in this Either instance.
Declaration
public Either<TA, TRes> MapRight<TRes>(Func<TB, TRes> map)
Parameters
Type | Name | Description |
---|---|---|
Func<TB, TRes> | map | The function to apply to the right value if this is a Right. |
Returns
Type | Description |
---|---|
Either<TA, TRes> | A new Either instance with the transformed right value. |
Type Parameters
Name | Description |
---|---|
TRes | The type of the transformed right value. |
Map<TRes1, TRes2>(Func<TA, TRes1>, Func<TB, TRes2>)
Maps the values contained in this Either instance using the provided functions.
Declaration
public Either<TRes1, TRes2> Map<TRes1, TRes2>(Func<TA, TRes1> map1, Func<TB, TRes2> map2)
Parameters
Type | Name | Description |
---|---|---|
Func<TA, TRes1> | map1 | The function to apply to the left value if this is a Left. |
Func<TB, TRes2> | map2 | The function to apply to the right value if this is a Right. |
Returns
Type | Description |
---|---|
Either<TRes1, TRes2> | A new Either instance with transformed values. |
Type Parameters
Name | Description |
---|---|
TRes1 | The type of the left result. |
TRes2 | The type of the right result. |
ToLeft()
Converts this instance to a Left instance.
Declaration
public Left<TA, TB> ToLeft()
Returns
Type | Description |
---|---|
Left<TA, TB> | A new Left instance containing the left value. |
ToRight()
Converts this instance to a Right instance.
Declaration
public Right<TA, TB> ToRight()
Returns
Type | Description |
---|---|
Right<TA, TB> | A new Right instance containing the right value. |
Operators
| Edit this page View Sourceimplicit operator Either<TA, TB>(Left<TA>)
Performs an implicit conversion from Left<T> to Either<TA, TB>.
Declaration
public static implicit operator Either<TA, TB>(Left<TA> left)
Parameters
Type | Name | Description |
---|---|---|
Left<TA> | left | The object to convert |
Returns
Type | Description |
---|---|
Either<TA, TB> | The result of the conversion. |
implicit operator Either<TA, TB>(Right<TB>)
Performs an implicit conversion from Right<T> to Either<TA, TB>.
Declaration
public static implicit operator Either<TA, TB>(Right<TB> right)
Parameters
Type | Name | Description |
---|---|---|
Right<TB> | right | The object to convert |
Returns
Type | Description |
---|---|
Either<TA, TB> | The result of the conversion. |