Struct Option<T>
Represents an option type that can contain a value or be empty (None).
Inherited Members
Namespace: MediatorForge.Results
Assembly: MediatorForge.dll
Syntax
public readonly struct Option<T>
Type Parameters
Name | Description |
---|---|
T | The type of the value. |
Properties
| Improve this Doc View SourceIsNone
Gets a value indicating whether this instance does not contain a value.
Declaration
public readonly bool IsNone { get; }
Property Value
Type | Description |
---|---|
System. |
IsSome
Gets a value indicating whether this instance contains a value.
Declaration
public readonly bool IsSome { get; }
Property Value
Type | Description |
---|---|
System. |
None
Gets an instance of Option<T> that represents no value.
Declaration
public static readonly Option<T> None { get; }
Property Value
Type | Description |
---|---|
Option<T> |
Methods
| Improve this Doc View SourceCompareTo(Option<T>)
Compares this instance with another Option<T> and returns an integer that indicates whether this instance precedes, follows, or occurs in the same position in the sort order as the other Option<T>.
Declaration
public readonly int CompareTo(Option<T> other)
Parameters
Returns
Type | Description |
---|---|
System. |
A value that indicates the relative order of the objects being compared. |
Equals(Option<T>)
Determines whether this instance and another specified Option<T> have the same value.
Declaration
public readonly bool Equals(Option<T> other)
Parameters
Returns
Type | Description |
---|---|
System. |
|
Equals(Object)
Determines whether the specified object is equal to this instance.
Declaration
public override readonly bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System. |
obj | The object to compare with this instance. |
Returns
Type | Description |
---|---|
System. |
|
Overrides
GetHashCode()
Returns the hash code for this instance.
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
System. |
A hash code for the current object. |
Overrides
Match(Action<T>, Action)
Executes one of the specified functions based on whether this instance contains a value.
Declaration
public readonly void Match(Action<T> onSome, Action onNone)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | onSome | The function to execute if this instance contains a value. |
Action | onNone | The function to execute if this instance does not contain a value. |
Match<TResult>(Func<T, TResult>, Func<TResult>)
Executes one of the specified functions based on whether this instance contains a value.
Declaration
public readonly TResult Match<TResult>(Func<T, TResult> onSome, Func<TResult> onNone)
Parameters
Type | Name | Description |
---|---|---|
Func<T, TResult> | onSome | The function to execute if this instance contains a value. |
Func<TResult> | onNone | The function to execute if this instance does not contain a value. |
Returns
Type | Description |
---|---|
TResult | The result of the executed function. |
Type Parameters
Name | Description |
---|---|
TResult | The type of the result produced by the functions. |
OnNone(Action)
Executes the specified action if this instance does not contain a value.
Declaration
public readonly void OnNone(Action onNone)
Parameters
Type | Name | Description |
---|---|---|
Action | onNone | The action to execute if this instance does not contain a value. |
OnSome(Action<T>)
Executes the specified action if this instance contains a value.
Declaration
public readonly void OnSome(Action<T> onSome)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | onSome | The action to execute if this instance contains a value. |
Some(T)
Creates an instance of Option<T> that contains a value.
Declaration
public static Option<T> Some(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to be contained. |
Returns
Operators
| Improve this Doc View SourceEquality(Option<T>, Option<T>)
Determines whether two Option<T> instances are equal.
Declaration
public static bool operator ==(Option<T> left, Option<T> right)
Parameters
Type | Name | Description |
---|---|---|
Option<T> | left | The first Option<T> to compare. |
Option<T> | right | The second Option<T> to compare. |
Returns
Type | Description |
---|---|
System. |
|
GreaterThan(Option<T>, Option<T>)
Determines whether one Option<T> instance follows another in the sort order.
Declaration
public static bool operator>(Option<T> left, Option<T> right)
Parameters
Type | Name | Description |
---|---|---|
Option<T> | left | The first Option<T> to compare. |
Option<T> | right | The second Option<T> to compare. |
Returns
Type | Description |
---|---|
System. |
|
GreaterThanOrEqual(Option<T>, Option<T>)
Determines whether one Option<T> instance follows or is equal to another in the sort order.
Declaration
public static bool operator >=(Option<T> left, Option<T> right)
Parameters
Type | Name | Description |
---|---|---|
Option<T> | left | The first Option<T> to compare. |
Option<T> | right | The second Option<T> to compare. |
Returns
Type | Description |
---|---|
System. |
|
Implicit(T to Option<T>)
Implicitly converts a value to an Option<T> containing that value.
Declaration
public static implicit operator Option<T>(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to convert. |
Returns
Type | Description |
---|---|
Option<T> |
Inequality(Option<T>, Option<T>)
Determines whether two Option<T> instances are not equal.
Declaration
public static bool operator !=(Option<T> left, Option<T> right)
Parameters
Type | Name | Description |
---|---|---|
Option<T> | left | The first Option<T> to compare. |
Option<T> | right | The second Option<T> to compare. |
Returns
Type | Description |
---|---|
System. |
|
LessThan(Option<T>, Option<T>)
Determines whether one Option<T> instance precedes another in the sort order.
Declaration
public static bool operator <(Option<T> left, Option<T> right)
Parameters
Type | Name | Description |
---|---|---|
Option<T> | left | The first Option<T> to compare. |
Option<T> | right | The second Option<T> to compare. |
Returns
Type | Description |
---|---|
System. |
|
LessThanOrEqual(Option<T>, Option<T>)
Determines whether one Option<T> instance precedes or is equal to another in the sort order.
Declaration
public static bool operator <=(Option<T> left, Option<T> right)
Parameters
Type | Name | Description |
---|---|---|
Option<T> | left | The first Option<T> to compare. |
Option<T> | right | The second Option<T> to compare. |
Returns
Type | Description |
---|---|
System. |
|